#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
typedef long long ll;
/* define */
#define sf(a) scanf("%d",&a)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define rep1(i,a,b) for(int i=(a);i<(b);i++)
#define clr(num) memset(num,0,sizeof(num))
#define pf(a) printf("%d\n",a)
/* define */
const int N = 5000;
const int inf = 1<<29;
int f[6*N],p[6*N],cnt=1;
int num[6*N];
void init(){
for(int i=2;i<=5*N;i++){
if(!f[i])
p[cnt++]=i;
for(int j=i+i;j<=5*N;j+=i){
f[j]=1;
}
}
}
int get_P(int n,int x){
if(n==0)
return 0;
return n/x+get_P(n/x,x);
}
int main(){
int n,m,t;
init();
sf(t);
rep(i,1,t){
sf(m),sf(n);
int k=1;
clr(num);
while(1){
while(m%p[k]==0){
m/=p[k];
num[k]++;
}
k++;
if(m==1)
break;
}
int ans=inf;
rep1(ii,1,k){
if(num[ii]==0) continue;
ans=min(ans,get_P(n,p[ii])/num[ii]);
}
printf("Case %d:\n",i);
if(ans!=0)
pf(ans);
else
puts("Impossible to divide");
}
return 0;
}
08-15
08-15
08-15