#include <bits/stdc++.h>
using namespace std;
const int N=1000000+5;
bool win[N]={0};
inline int mx(int x){
int t=0;
while(x!=0){
if (x%10!=0)t=max(t,x%10);
x/=10;
}
return t;
}
inline int mn(int x){
int t=10;
while(x!=0){
if (x%10!=0)t=min(t,x%10);
x/=10;
}
return t;
}
int main(){
freopen ("cdgame.in","r",stdin);
freopen ("cdgame.out","w",stdout);
win[0]=0;
for (int i=1;i<=9;i++)win[i]=1;
for (int i=10;i<=1e6;i++){
win[i]=1^(win[i-mx(i)]&win[i-mn(i)]);
}
int T;scanf("%d",&T);
while(T--){
int n;scanf("%d",&n);
(win[n])?printf("YES\n"):printf("NO\n");
}
return 0;
}