//package com.company;

import java.util.*;

public class prog {

    public static boolean check(Integer x, Integer y, Integer z, Integer q) {

        if (x*10+y >= 24 || z*10+q >=60) {
            return false;
        }

        if ((z == 0) && (q == 0)) {
            return true;
        }
        if (x.equals(z) && y.equals(q)) {
            return true;
        }
        if (x.equals(q) && y.equals(z)) {
            return true;
        }
        if (y.equals(x+1) && z.equals(y+1) && q.equals(z+1)) {
            return true;
        }
        Integer aux = x*1000+y*100+z*10+q;
        if (aux == 1024 || aux == 2048 || aux == 4096 || aux == 8192) {
            return true;
        }

        return false;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        String t = sc.nextLine();

        Integer o = Integer.parseInt("" + t);

        while (o-- >= 0) {
            String time = sc.nextLine();

            Integer x = Integer.parseInt("" + time.charAt(0));
            Integer y = Integer.parseInt("" + time.charAt(1));
            Integer z = Integer.parseInt("" + time.charAt(3));
            Integer q = Integer.parseInt("" + time.charAt(4));

            if (prog.check(x,y,z,q)) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }

        }

        System.exit(0);

    }
}