I am getting Wa on test file 2 I couldn’t debug it can someone point me out where my code fails.
#include <iostream>
using namespace std;
#include<vector>
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("op.txt","w",stdout);
#endif
int tc;
cin>>tc;
while(tc--){
long long n,d;
cin>>n>>d;
for(long long i=0;i<n;i++) {
long long p,x=0,m,ans=0;
cin>>p;
m=p;
if(m%d==0) { cout<<"YES\n"; continue; }
while(m!=0){
if(d==m%10 ) { cout<<"YES\n"; goto last;}
m/=10;
}
while(p-d>0){
p-=d;
if(p%10==0 || p%d==0 || p%10==d) { ans=1; break; }
}
if(ans) cout<<"YES\n";
else cout<<"NO\n";
last:
ans=0;
}
}
}