var s:string; n,i:byte; x,h,m:integer; ok:boolean; begin //assign(input,'a.in');reset(input); //assign(output,'a.out');rewrite(output); readln(n); for i:=1 to n do begin ok:=false; readln(s); delete(s,3,1); val(copy(s,1,2),h); val(copy(s,3,2),m); if (h<24)and(m<60)then begin val(s,x); if (m=0)then ok:=true; if (h=m)then ok:=true; if (s[1]=s[4])and(s[2]=s[3])then ok:=true; if (ord(s[1])=(ord(s[2])-1))and(ord(s[2])=(ord(s[3])-1))and (ord(s[3])=(ord(s[4])-1))then ok:=true; if x>1 then begin while (x mod 2=0) do x:=x div 2; if x=1 then ok:=true;end; end; if ok then writeln('YES') else writeln('NO'); end; end.