var
n,i,g,max,min:longint;
f:array[0..2000000]of boolean;
a:array[0..10000]of longint;
procedure work(k:longint);
var
now:longint;
begin
min:=maxlongint;
max:=-maxlongint;
while k>0 do
begin
now:=k mod 10;
k:=k div 10;
if now=0 then continue;
if now>max then max:=now;
if now<min then min:=now;
end;
end;
begin
assign(input,'cdgame.in'); reset(input);
assign(output,'cdgame.out'); rewrite(output);
readln(g);
n:=0;
for i:=1 to g do
begin
readln(a[i]);
if a[i]>n then n:=a[i];
end;
f[0]:=false;
for i:=1 to 9 do f[i]:=true;
for i:=10 to n do
begin
work(i);
if (not f[i-max])or(not f[i-min]) then f[i]:=true
else f[i]:=false;
end;
for i:=1 to g do
if f[a[i]] then writeln('YES')
else writeln('NO');
close(input);
close(output);
end.