import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String args[]){ // File file = new File("src/input.txt"); BufferedReader br = null; Scanner keyboard = new Scanner(System.in); int myint = keyboard.nextInt(); String enter = keyboard.nextLine(); // try { // br = new BufferedReader(new FileReader(file)); // } catch (FileNotFoundException e1) { // // TODO Auto-generated catch block // e1.printStackTrace(); // } String line; int lineNr; // lineNr = Integer.parseInt(br.readLine()); for (int i=0; i < myint; i++){ line = keyboard.nextLine(); boolean ok = false; //System.out.println(line); String p1 = line.substring(0, line.indexOf(':')); String p2 = line.substring(line.indexOf(':')+1,line.length()); //System.out.println(p1+p2); if (Integer.parseInt(p1)<24 && Integer.parseInt(p2)<60){ if (p2.equals("00")){ System.out.println("YES"); ok = true; } if (!ok) if (p1.equals(p2)){ System.out.println("YES"); ok = true; } if (!ok) if (p1.charAt(0) == p2.charAt(1) && p1.charAt(1) == p2.charAt(0)){ System.out.println("YES"); ok = true; } int one; int two; int three; int four; one = p1.charAt(0)-48; two = p1.charAt(1)-48; three = p2.charAt(0)-48; four = p2.charAt(1)-48; //System.out.println(one+" "+two); if (!ok) if (one+1 == two && two+1 == three && three+1 == four){ System.out.println("YES"); ok = true; } if (!ok){ System.out.println("NO"); } } else System.out.println("NO"); } // try { // br.close(); // } catch (IOException e) { // // TODO Auto-generated catch block // e.printStackTrace(); // } } }