var s:string; n,i:integer; peculiar,valid:boolean; begin readln(n); for i:=1 to n do begin readln(s); peculiar:=false; if (s[4]='0') and (s[5]='0') then peculiar:=true; if (s[1]=s[4]) and (s[2]=s[5]) then peculiar:=true; if (s[1]=s[5]) and (s[2]=s[4]) then peculiar:=true; if (s='01:23') or (s='12:34') or (s='23:45') then peculiar:=true; if (s='10:24') or (s='20:48') then peculiar:=true; valid:=true; if s[1] > '2' then valid:=false; if (s[1] = '2') and (s[2] >= '4') then valid := false; if s[4] >'5' then valid:=false; if (valid) and (peculiar) then writeln('YES') else writeln('NO'); end; end.