#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define mx 100005
#define nn "\n"
#define sp " "
#define MIN(a, b, c) min(a, min(b, c))
#define MAX(a, b, c) max(a, max(b, c))
#define mp make_pair
#define ll long long int
#define loop(i, n, a) for (i = a; i < n; ++i)
#define dloop(i, n) for (i = n - 1; i > 0; --i)
#define test while (t--)
#define all(s) s.begin(), s.end()
#define fast ios_base::sync_with_stdio(false)
#define setp(n) fixed << setprecision(n)

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef map<int, int> mi;
typedef map<ll, ll> ml;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;

void yay(ll flag)
{
    if (flag == 0)
        cout << "NO";
    else
        cout << "YES";
    cout << endl;
}

template <typename T>
void unq(vector<T> &vec)
{
    sort(all(vec));
    vec.erase(unique(all(vec)), vec.end());
}

template <typename T>
void dsp(vector<T> &v, ll n, ll a=0)
{
    ll i;
    loop(i, n, a)
    {
        cout << v[i] << sp;
    }
    cout << nn;
}

template <typename T>
void input(vector<T> &v, ll n)
{
    ll i;
    T x;
    loop(i, n, 0)
    {
        cin >> x;
        v.pb(x);
    }
}

int eve(ll x)
{
    if (x % 2 == 0)
        return 1;
    return 0;
}

const ll inf = 1e17 + 7;
const int infi = 1e9 + 7;
const ll dd = 8e7 + 7;
const ll mod = 1e9 + 7;

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

void solve()
{
   int i,x,n,d,f;
   cin>>n>>d;
    loop(i,n,0)
    {
        cin>>x;
        f=0;
        while(x>=d)
        {
            if(digit(x,d))
            {
                f=1;
                break;
            }
            x-=d;
        }
        yay(f);
    }
}
int main()
{
    fast;
    int t = 1;
    cin >> t;
    test
    {
        solve();
      //  cout << nn;
    }
}
