#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n;
bool q[1000001]={0};
int main()
{
freopen ("cdgame.in","r",stdin);
freopen ("cdgame.out","w",stdout);
for (int i=1;i<=1000000;i++)
{
int a=0,b=10;
int c;
c=i;
while (c)
{
int d;
d=c%10;
if (d>a)
a=d;
if (d<b&&d!=0)
b=d;
c/=10;
}
if (b==0)
{
q[i]=1-q[i-a];
}
else
{
q[i]=(!q[i-a]||!q[i-b]);
}
}
cin>>n;
for (int i=0;i<n;i++)
{
int p;
cin>>p;
if (q[p]==0)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
return 0;
}