#include <iostream>
#include <cstdlib>
using namespace std;

bool OK(int a, int b, int c, int d);

int main()
{
    char a[6];
    int n;
    cin >> n;
    for ( ; n; n-- )
    {
        cin >> a;
        int b = a[0] - 48;
        int c = a[1] - 48;
        int d = a[3] - 48;
        int e = a[4] - 48;
        int n = b * 10 + c;
        int m = d * 10 + e;
        if ( OK(b, c, d, e) )
            cout << "YES\n";
        else
            cout << "NO\n";
    }
    return 0;
}

bool OK( int a, int b, int c, int d)
{
    if ( a * 10 + b < 0 || a * 10 + b > 24 ) return false;
    if ( c * 10 + d < 0 || c * 10 + d > 60 ) return false;
    if ( c == 0 && d == 0 ) return true;
    if ( a == c && b == d ) return true;
    if ( a == d && b == c ) return true;
    if ( d == c + 1 && c == b + 1 && b == a + 1 ) return true;
    int x = a * 1000 + b * 100 + c * 10 + d;
    if ( x == 1024 || x == 2048 ) return true;
    return false;

}