#include <bits/stdc++.h>
using namespace std;
int t, q, d, x;
 
int main()
{   //freopen("Test.inp", "r", stdin);
    //freopen("Test.out", "w", stdout);
 
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 
    cin >> t;
 
    while (t--)
    {   cin >> q >> d;
 
        for (int i = 1; i <= q; ++i)
        {   cin >> x; string ans = "NO";
 
            if (x >= d * 10) ans = "YES";
            else
            {   while (x >= 0)
                {   int y = x;
 
                    while (y)
                    {   if (y % 10 == d)
                        {   x = 0; y = 0; ans = "YES";  }
 
                        y /= 10;
                    }
 
                    x -= d;
                }
            }
 
            cout << ans << '\n';
        }
 
    }
 
    return 0;
}