import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class prog { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { String line = br.readLine(); boolean isPec = isPec(line); if (isPec) { System.out.println("YES"); } else { System.out.println("NO"); } } } static boolean isPow2(String s1) { if (s1.charAt(0) != '1') { return false; } int s1l = s1.length(); for (int i = 1; i < s1l; i++) { if (s1.charAt(i) != '0') { return false; } } return true; } static boolean isPec(String s) { if (s == null || s.length() != 5) { return false; } int hours = Integer.parseInt(s.substring(0, 2)); int minutes = Integer.parseInt(s.substring(3)); if ((hours > 24) || (minutes > 60) || ((hours == 24) && (minutes > 0))) { return false; } if (minutes == 0) { return true; } if (s.substring(0, 2).equals(s.substring(3))) { return true; } if (s.substring(0, 2).equals(s.substring(4) + s.substring(3, 4))) { return true; } int i1 = Integer.parseInt(s.substring(0, 1)); int i2 = Integer.parseInt(s.substring(1, 2)); int i3 = Integer.parseInt(s.substring(3, 4)); int i4 = Integer.parseInt(s.substring(4)); if ((i2 == (i1 + 1)) && (i3 == i2 + 1) && (i4 == i3 +1)) { return true; } String s2 = s.replace(":", ""); int pw = Integer.parseInt(s2); if (!s2.startsWith("0") && isPow2(Integer.toString(pw, 2))) { return true; } return false; } }