#include<bits/stdc++.h>
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int>>
#define MX              200005
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define ull unsigned long long
#define ll long long

void sbs()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.in", "w", stdout);
    #endif
}

void add(int &a,int b) {
    a+=b;
    if(a>=mod)
        a-=mod;
}
int nCr(int m, int n){

    //6 * 5 * 4 *../ 1*2*3*...
    int ans = 1;
    for (int i = 1; i <= n; i++){
        ans = ans * (m - i + 1) / i;
        ans %= mod;
 
    }
    return ans;
}

int isPrime(int n){
    for(int i=2;i*i<=n;i++){
        if(n%i==0)
            return 0;
    }
    return 1;
}

int power(int a,int b,int m){
    if(a == 1)return 1;
    if(b == 1)return a%m;
    int small = power(a,b/2,m);
    small = (small * small) %m;
    if(b & 1)
        small = (small * a)%m;
    return small % m;
}

int check(int p, int d) {
    int f = 0;
    while(p) {
        int dig = p % 10;
        if(dig == d)f = 1;
        p /= 10;
    }
    return f;
}

int32_t main()
{
    sbs();
    int t;cin>>t;
    int cas = 0;

    int a[10][10];
    for (int i=1;i<=9;i++) {
        for (int j=1;j<=9;j++) {
            if (i == j)
                continue;
            for (int k = 1;;k++) {
                if (check(i + k * j, j)) {
                    a[i][j] = k;
                    break;
                }
            }
        }
    }
    while(t--){
        int n;cin>>n;
        int d;cin>>d;
        for(int i=0;i<n;i++) {
            int m;cin>>m;
            int p = m;
            int f = 0;
            while(p) {
                int dig = p % 10;
                if(dig == d)f = 1;
                p /= 10;
            }
            if(d == 1 || f == 1 || m % d == 0) {
                cout<<"yes"<<endl;
            }else {
                int x = m / d;
                int y = m % d;
                if(y == 0) {
                    cout<<"yes"<<endl;
                }else if(a[y][d] > x) {
                    cout<<"no"<<endl;
                }else cout<<"yes"<<endl;
            }
        }
    }
    return 0;
}
    