#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
using namespace std;
__int64 gcd(__int64 a,__int64 b)
{
if (!b)
return a;
return gcd(b, a % b);
}
int main()
{
__int64 total;
scanf("%I64d",&total);
__int64 k=1;
while(total--)
{
__int64 a,b;
scanf("%I64d %I64d",&a,&b);
__int64 h=gcd(a,b);
if(a==1)
{
printf("Case #%I64d: YES\n",k++);
continue;
}
while(a!=1)
{
a/=h;
h=gcd(a,b);
if(a!=1&&h==1)
{
printf("Case #%I64d: NO\n",k++);
break;
}
}
if(a==1)
{
printf("Case #%I64d: YES\n",k++);
continue;
}
}
return 0;
}