#include <cstdio>

using namespace std;

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

int main() {
    int t;
    scanf("%d", &t);
    
    while(t--) {
        int n, d, temp, i;
        scanf("%d%d", &n, &d);
        
        bool flag;
        
        int a[n];
        for (i = 0; i < n; i++)
            scanf("%d", &a[i]);
            
        for (i = 0; i < n; i++) {
            temp = a[i]%d;
            
            flag = false;
            
            while (temp <= a[i]) {
                if (check(temp, d)) {
                    flag = true;
                    break;
                }
                
                temp += d;
            }
            
            flag ? printf("YES\n") : printf("NO\n");
        }
    }
    
    return 0;
}