#include<fstream>
#include<memory.h>
using namespace std;
bool f[10000001];
int i,j,k,maxa,mina,n,x,p;
int c[101];
int o[10]={0,1,10,100,1000,10000,1000000,10000000,100000000,1000000000};
int a[10];
int main()
{
ifstream fin("cdgame.in");
ofstream fout("cdgame.out");
fin>>n;
p=0;
for (i=1;i<=n;i++)
{
fin>>c[i];
if (c[i]>p)
p=c[i];
}
f[0]=false;
for (i=1;i<=10;i++)
f[i]=true;
f[10]=false;
for (i=10;i<=p;i++)
{
for (j=1;j<=7;j++)
{
int y=i;
y=i%o[j+1];
y=y/o[j];
a[j]=y;
}
maxa=0;
mina=1000000000;
for(j=1;j<=7;j++)
{
if ((a[j]!=0)or(a[j]>maxa)) maxa=a[j];
if ((a[j]!=0)or(a[j]<mina)) mina=a[j];
}
f[i]=(!f[i-maxa])|(!f[i-mina]);
}
for (i=1;i<=n;i++)
{
if (f[c[i]]) fout<<"YES"<<endl;
if (not(f[c[i]])) fout<<"NO"<<endl;
}
fin.close();
fout.close();
return 0;
}