#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int t;
    int d, n;

    scanf("%d", &t);
    for (int i = 0; i < t; i++) {
        scanf("%d%d", &n, &d);
        for (int num, ge, tt, j = 0; j < n; j++) {
            scanf("%d", &num);
            ge = num%10;
            tt = num;
            int flag = 0;
            if (num>=d*10+d) flag = 1;
            while (!flag && tt>0) {
                if (tt%10 == d) flag = 1;
                tt /= 10;
            }
            for (int k = 1; !flag && k < 11; k++) {
                if (ge == (d*k)%10 && d*k<=num) {
                    flag = 1;
                    break;
                } else if (d*k > num)
                    break;
            }
            if (flag) printf("YES\n");
            else printf("NO\n");
        }
    }

    return 0;
}
