#include <bits/stdc++.h>
#define ll long long
using namespace std;
bool lucky(ll x, ll d){
	ll temp = x;
	bool ans = false;
	while(x > 0 and temp > 0){
		ll q = temp%10;
		temp = temp/10;
		if(q==d){
			ans = true;
			break;
		}
		if(temp==0){
			x = x - d;
			temp = x;
		}
	}
	return ans;
}
void solve(){
    ll n, d;
    cin>>n>>d;
    ll a[n];
    for (int i = 0; i < n; ++i)
    {
    	cin>>a[i];
    }
    for (int i = 0; i < n; ++i)
    {
    	ll x = a[i];
    	if(x >= 10*d){
    		cout<<"YES"<<endl;
    	}
    	else{
    		if(lucky(x, d)){
    			cout<<"YES"<<endl;
    		}
    		else{
    			cout<<"NO"<<endl;
    		}
    	}
    }
}
int main(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
  int t = 1;
  cin>>t;
  while(t--){
    solve();
  }
}