#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll __int64
#define mod 1000000007
#define inf 100000000000005
#define MAXN 10000010
#define pi 4*atan(1)
#define esp 0.000000001
//#pragma comment(linker, "/STACK:102400000,102400000")
struct is
{
ll a[10][10];
};
ll x,m,k,c;
is juzhenmul(is a,is b,ll hang ,ll lie)
{
int i,t,j;
is ans;
memset(ans.a,0,sizeof(ans.a));
for(i=1;i<=hang;i++)
for(t=1;t<=lie;t++)
for(j=1;j<=lie;j++)
{
ans.a[i][t]+=(a.a[i][j]*b.a[j][t]);
ans.a[i][t]%=k;
}
return ans;
}
is quickpow(is ans,is a,ll x)
{
while(x)
{
if(x&1) ans=juzhenmul(ans,a,2,2);
a=juzhenmul(a,a,2,2);
x>>=1;
}
return ans;
}
int main()
{
ll x,y,z,i,t;
int T,flag=1;
scanf("%d",&T);
while(T--)
{
scanf("%I64d%I64d%I64d%I64d",&x,&m,&k,&c);
is ans,base;
memset(ans.a,0,sizeof(ans.a));
ans.a[1][1]=1;
ans.a[2][2]=1;
base.a[1][1]=10;
base.a[1][2]=0;
base.a[2][1]=1;
base.a[2][2]=1;
is gg;
gg.a[1][1]=x;
gg.a[1][2]=x;
ans=quickpow(ans,base,m-1);
ans=juzhenmul(gg,ans,2,2);
//printf("%I64d\n",ans.a[1][1]);
printf("Case #%d:\n",flag++);
if(ans.a[1][1]==c)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}