#include<bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a) - 1; i>=(b);i--)
#define rep(i,n) FOR(i,0,n)
#define PB push_back
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FILL(a, value) memset(a, value, sizeof(a))
#define IOS ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0);


typedef  long long LL ;
typedef  vector<int > VI ;
typedef vector<LL > VL;
typedef pair<int,int > PII;
typedef pair<LL,LL> PLL;

const LL LINF = (LL)1e18 +47;
const int INF =  (int)1e9  +47 + (int)1e8  ;
const int MOD =(int)1e9 + 7 ;
const int modulo = 998244353. ;
const int nax = 2 * (int)1e5  + 10;
const double EPS = 1e-7;
const double PI = acos(-1.0);

const int MAX = 222;

int ans[10][125]; 
bool check(int x ,int d )
{
	 if(x % 10 == d)return true;
	 if((x / 10 ) % 10 == d)return true;
	 if((x / 100) %  10 == d)return true; 
	 return false;
}
int main() {
    IOS;
  //  freopen("C:\\pocketcpp\\QuickStart\\test.txt","r",stdin);
	// cout <<check(25,7) << endl;
     rep(i,10)ans[i][0] = 1;	
	 FOR(d,1,10)
	 {
		 VI vec;
		 
		 FOR(x,d,120)
		 {
			 if(check(x,d))
			 {
				 vec.PB(x); 
			 }
			 rep(j,SZ(vec))
			 {
				 if(ans[d][x - vec[j]])ans[d][x] = true; 
			 }
		 }
	 }
	int tt;
	cin >> tt;
	FOR(test,1,tt + 1)
	{
		int q,d;
		cin >> q >> d;
		rep(qq,q)
		{
			int x;
			cin >> x;
			if(x>=115)cout <<"YES\n";
			else 
			{
				if(ans[d][x])cout << "YES\n";
				else cout << "NO\n"; 
			}
		}		
	}
      
}