program peculiar;
var n,i,nr1,nr2:byte; x,y,z,t:char; nr,er,er1,er2:integer; s,s1,s2:string; c:boolean;
begin
readln(n);
for i:=1 to n do begin
        readln(s); c:=false;
        x:=s[1]; y:=s[2]; z:=s[4]; t:=s[5];
        s1:=x+y; s2:=z+t;
        val(s1,nr1,er1); val(s2,nr2,er2);
        if (nr1<24) and (nr2<60) then begin
        if (z='0') and (t='0') then c:=true;
        if (x=z) and (y=t) then c:=true;
        if (x=t) and (y=z) then c:=true;
        if (ord(x)=ord(y)-1) and (ord(y)=ord(z)-1) and (ord(z)=ord(t)-1) then c:=true;
        delete(s,3,1); val(s,nr,er); if (nr=1024) or (nr=2048) then c:=true;
        end
        else c:=false;
        if c then writeln('YES') else writeln('NO');
        end;
end.