#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
LL PowMod(LL a,LL b,LL MOD){
LL ret=1;
while(b){
if(b&1) ret=(ret*a)%MOD;
a=(a*a)%MOD;
b>>=1;
}
return ret;
}
int main(){
LL x, m , k, c;
int t;
cin>>t;
for(int i = 1; i <= t; i++){
scanf("%I64d %I64d %I64d %I64d", &x, &m, &k, &c);
k *= 9;
LL a = ((PowMod(10, m, k) + k - 1) % k) * x %k;
LL b = (9 *c) % k;
printf("Case #%d:\n",i);
if(a == b){
printf("Yes\n");
}else{
printf("No\n");
}
}
return 0;
}