#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define int long long
using namespace std;

bool isLucky(int x, int d) {
	while (x) {
		if (x % 10 == d)
			return true;
		x = x / 10;
	}
	return false;
}

signed main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	while (t--) {
		int q, d;
		cin >> q >> d;
		rep(i, q) {
			int x;
			cin >> x;
			if (d == 1) {
				cout << "YES\n";
				continue;
			}
			if (isLucky(x, d)) {
				cout << "YES\n";
				continue;
			}
			bool flag = false;
			for (int i = d; i <= x; i += d) {
				if (isLucky(x - i, d)) {
					flag = true;
					break;
				}
			}
			if (flag)
				cout << "YES";
			else cout << "NO";
			cout << "\n";
		}
	}

}