#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int get(int n, int m)
{
    int sum = 0;
    while (n)
    {
        sum += n / m;
        n /= m;
    }
    return sum;
}
bool notPrime[5005];
int primes[5005], pcnt;
int main()
{
    for (int i = 2; i < 5005; i++)
        if (!notPrime[i])
        {
            primes[pcnt++] = i;
            for (int j = i * i; j < 5005; j += i)
                notPrime[j] = true;
        }
    int T, m, n;
    scanf("%d", &T);
    for (int t = 1; t <= T; t++)
    {
        scanf("%d%d", &m, &n);
        int ans = numeric_limits<int>::max();
        for (int i = 0; primes[i] <= m; i++)
            if (m % primes[i] == 0)
            {
                int cnt = 0;
                for (int j = m; j % primes[i] == 0; j /= primes[i])
                    cnt++;
                if (cnt)
                    ans = min(ans, get(n, primes[i]) / cnt);
            }
        printf("Case %d:\n", t);
        if (ans)
            printf("%d\n", ans);
        else
            puts("Impossible to divide");
    }
    return 0;
}
