import java.util.*; // IT IS IMPORTANT THAT YOUR CLASS HAS THE NAME PROG! class prog { public static void main(String[] args) throws java.lang.Exception { Scanner scanner = new Scanner(System.in); //String vocale = "aeiou"; int t = Integer.parseInt(scanner.next().trim()); for (int i = 0; i < t; i++) { String s = scanner.next(); int n = ((int) s.charAt(0) - 48) * 10 + (int) s.charAt(1) - 48; int m = ((int) s.charAt(3) - 48) * 10 + (int) s.charAt(4) - 48; if (((n >= 0) && (n < 24)) && (m >= 0) && (m < 60)) { if (s.charAt(3) == '0' && s.charAt(4) == '0') { System.out.println("YES"); } else if (s.charAt(0) == s.charAt(3) && s.charAt(1) == s.charAt(4)) { System.out.println("YES"); } else if (s.charAt(0) == s.charAt(4) && s.charAt(1) == s.charAt(3)) { System.out.println("YES"); } else if (s.charAt(0) == s.charAt(4) && s.charAt(1) == s.charAt(3)) { System.out.println("YES"); } else if (s.charAt(0) == '0' && s.charAt(1) == '1' && s.charAt(3) == '2' && s.charAt(4) == '3') { System.out.println("YES"); } else if (s.charAt(0) == '1' && s.charAt(1) == '2' && s.charAt(3) == '3' && s.charAt(4) == '4') { System.out.println("YES"); } else if (s.charAt(0) == '1' && s.charAt(1) == '0' && s.charAt(3) == '2' && s.charAt(4) == '4') { System.out.println("YES"); } else if (s.charAt(0) == '2' && s.charAt(1) == '0' && s.charAt(3) == '4' && s.charAt(4) == '8') { System.out.println("YES"); } else { System.out.println("NO"); } } else { System.out.println("NO"); } } //System.out.println(a + b); } }