#include<iostream>

using namespace std;

int main()
{
	int t;
	cin >> t;
	while(t -- )
	{
		int n,b;
		cin >> n >> b;
		while(n --)
		{
			int a,m,k,flag = 1,aa = 0;
			cin >> a;
			m = a;
			while(m != 0)
			{
				k = m % 10;
				if(k == b) 
				{
					cout << "YES" << endl;
					flag = 0;
					aa = 1;
					break;
				}
				m = m / 10;
			}
			if(flag)
			{
				for(int i = a - 1;i > 0;i -- )
				if(i % 10 == b || i / 10 == b)
				{
					int q;
					q = a - i;
					//cout <<"q"<< q<<endl;
					if(q % b == 0) 
					{
						cout << "YES" << endl;
						aa = 1;
						break ;
					}
			    while(q != 0)
			    {
				k = q % 10;
				if(k == b) 
				{
					cout << "YES" << endl;
					aa = 1;
					break;
				}
				q = q / 10;
                }
                if(aa) break;
				}
			}
			if(!aa) cout << "NO" << endl;
		}
	}
	return 0;
}