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<25)and(m<61)then begin val(s,x); if (s[3]='0')and(s[4]='0')then ok:=true; if (s[1]=s[3])and(s[2]=s[4])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)and(x>1) do x:=x div 2; if x=1 then ok:=true;end; end; if ok then writeln('YES') else writeln('NO'); end; end.