#include <iostream>

using namespace std;

int hasd( int d, int nr ) {
  while ( nr > 0 && nr % 10 != d ) {
    nr /= 10;
  }
  return ((nr % 10) == d);
}

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

  cin >> t;
  while ( t-- ) {
    cin >> n >> d;
    int lim = (d - 1) * 10 + 9;
    for ( int i = 0; i < n; ++i ) {
      cin >> a;
      if ( a > lim ) {
        cout << "YES\n";
      } else {
        int ok = 0;
        while ( !ok && a > 0 ) {
          ok = hasd( d, a );
          a -= d;
        }
        if ( ok ) {
          cout << "YES\n";
        } else {
          cout << "NO\n";
        }
      }
    }
  }
  return 0;
}