#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define rep(i, a, b, inc) for(long long i = a; i < b; i += inc)
#define REP(i, n) rep(i, 0, n, 1)

typedef unsigned long long ULL;
typedef long long ll;
typedef long double LD;

ll solve(ll a,ll d)
{
    while(a>0)
    {
        if(a%d==0)
            return 1;
        ll b = a;
        while(b>0)
        {
            if(b%10 == d)
                return 1;
            b/=10;
        }
        a-=10;
    }
    return 0;
}

int main()
{
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //cout.tie(NULL);
    ll T,n,d,c,a;
    cin>>T;
    while(T--)
    {
        cin>>n>>d;
        REP(i,n)
        {
            cin>>a;
            c=solve(a,d);
            cout<<((c)?"YES":"NO")<<endl;
        }
    }
    return 0;
}