#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define pb push_back
//#define x first
//#define y second
#define N 200005
class node{
	public:
	pair<int,int> p;
	int i;
	node(){}
	node(pair<int,int> pp,int ii):p(pp),i(ii){}
	node(const node& no):p(no.p),i(no.i){}
	bool operator<(const node& n2)const{
		return p<n2.p;
	}
};
int a[10005];
int main(){
	ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
//	freopen("test","r",stdin);
	int i,j,k,T;
	cin>>T;
	while(T--){
		int n,x,ans=-1,q,d;
		cin>>n>>d;
		for(i=1;i<=n;i++){
			cin>>k;
			int m=k;
			j=k;
			bool f=false;
			while(j){
				if(j%10==d)f=true;
				j/=10;
			}
			if(f){
				cout<<"YES\n";
				continue;
			}
			for(k=k%d;k<100&&k<=m;k+=d)
				if((k%10==d)||(k/10==d)){
					f=true;
					break;
				}
			cout<<(f?"YES":"NO")<<endl;
		}
	}
	return 0;
}