import java.util.Scanner; public class prog { public static boolean consec(String xy, String zt) { int x = Integer.parseInt(xy.substring(0, 1)); int y = Integer.parseInt(xy.substring(1)); int z = Integer.parseInt(zt.substring(0, 1)); int t = Integer.parseInt(zt.substring(1)); return y == x + 1 && z == x + 2 && t == x + 3; } public static boolean power(String s) { if (s.substring(0, 1).equals("0")) { return false; } int n = Integer.parseInt(s); return n != 0 && (n & (n - 1)) == 0; } public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < n; i++) { String time = scanner.nextLine(); String xy = time.substring(0, time.indexOf(':')); String zt = time.substring(time.indexOf(':') + 1); int nxy = Integer.parseInt(xy); int nzt = Integer.parseInt(zt); if (nxy >= 24 || nzt >= 60) { System.out.println("NO"); continue; } String tz = zt.substring(1) + zt.substring(0, 1); if (nzt == 0 || xy.equals(zt) || xy.equals(tz) || consec(xy, zt) || power(xy + zt)) { System.out.println("YES"); } else { System.out.println("NO"); } } scanner.close(); } }