// praskkorytnacky.cpp : Defines the entry point for the console application.
//
 
////////////////////////#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int skontroluj(int lucky,int cis)
{
	while (cis > 0)
	{
		if (cis % 10 == lucky)return 1;
		else cis = cis / 10;
	}
	return 0;
}
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, lucky;
		cin >> n >> lucky;
		int *pole = new int[n];
		bool ano = false;
		for (int i = 0; i < n; i++)
		{
			cin >> pole[i];
			ano=false;
			while (pole[i] > 0)
			{
				if (skontroluj(lucky, pole[i]))
				{
					ano = true;
					cout << "YES" << endl;
					break;
				}
				else
				{
					pole[i] = pole[i] - lucky;
				}
 
			}
			if (ano == false)
	{
		cout << "NO" << endl;
	}
		}
 
	}
 
    return 0;
}