import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class prog {
	
	public static void main(String args[]){
//		File file = new File("src/input.txt");
		//BufferedReader br = null;
		Scanner keyboard = new Scanner(System.in);
		List<String> list = new ArrayList<String>();
		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 && Integer.parseInt(p1)>=0  &&Integer.parseInt(p2)>=0){
				if (p2.equals("00")){
					System.out.println("YES");
					list.add("YES");
					ok = true;
				}
				if (!ok)
				if (p1.equals(p2)){
					System.out.println("YES");
					list.add("YES");
					ok = true;
				}
				if (!ok)
				if (p1.charAt(0) == p2.charAt(1) && p1.charAt(1) == p2.charAt(0)){
					list.add("YES");
					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){
					list.add("YES");
					System.out.println("YES");
					ok = true;
				}
				if (!ok){
					list.add("NO");
					System.out.println("NO");
				}
				
			}
			else{
			list.add("NO");
			System.out.println("NO");
			}
		}
//		for (String i :list){
//			System.out.println(i);
//		}
//		try {
//			br.close();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
}