#include <bits/stdc++.h>
using namespace std;
bool check(long int n,int d)
{
    int temp=n%10;
    while(n>0)
    {
        
        if(temp==d)
            return 0;
        n=n/10;
        temp=n%d;
    }
    return 1;
}

void solve(long int n,int d)
{
    if(n<=0){
        cout<<"NO\n";
        return;
    }
    if(n%d==0)
    {
        cout<<"YES\n";
        return;
    }
    else
    {
        solve(n-10,d);
    }
}

int main(void) {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
        int q,d,i;
        cin>>q>>d;
        long int a[q];
        for(i=0;i<q;i++)
        {
            cin>>a[i];
            if(a[i]>=(d*10) or a[i]%d==0)
            {
                cout<<"YES\n";
            }
            else
            {
                if(!check(a[i],d))
                {
                    cout<<"YES\n";
                }
                else
                {
                    solve(a[i]-d,d);    
                }
                
            }
        }
      // cout<<"\n";
	}
	return 0;
}

