#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)     for(long long int i=a; i<n; i++)
#define loop(i,a,n)     for(long long int i=a; i>=n; i--) 
int ans;
void check(vector<int>&v, int x, int sum)
{
	if(sum==x)
	{
		ans=1;
		return;
	}
	else if(sum>x)
	{
		return;
	}
	forr(i, 0, v.size())
	{
		check(v, x, sum+v[i]);
	}
}

int main()
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL);

	int m; cin>>m; while(m--)
	{
		int a, b;
		cin>>a>>b;
		forr(i, 0, a)
		{
			long long int x;
			cin>>x;
			if(x>=b*10)
			{
				cout<<"YES\n";
			}
			else
			{
				vector<int> v;
				forr(j, 0, 1+x)
				{
					string s=to_string(j);
					forr(k, 0, s.size())
					{
						if(s[k]-'0'==b)
							v.push_back(j);
					}				
				}
				check(v, x, 0);
				cout<<(ans==1?"YES\n":"NO\n");
				ans=0;
			}
			ans=0;
		}
	
	}
	
	return 0;
}