#include <fstream>
#include <iostream>
#define f cin
//#define g cout

using namespace std;

//ifstream f("date.in");
//ofstream g("date.out");

char c[10];
int n, h, m;

bool oglinda()
{
    if (c[0]==c[4] && c[1]==c[3]) return 1;
    return 0;
}

bool consecutive()
{
    if (c[0]+1==c[1] && c[1]+1==c[3] && c[3]+1==c[4]) return 1;
    return 0;
}

bool putere(int x)
{
    int p=1024;

    while (p<=x)
    {
        if (p==x) return 1;
        p*=2;
    }
    return 0;
}

int main()
{
    f>>n;
    while (n--)
    {
        f>>c;
        h=(c[0]-'0')*10+(c[1]-'0');
        m=(c[3]-'0')*10+(c[4]-'0');
        if (h<24 && m<60)
        {
            if (m==0) cout<<"YES\n";
            else
                if (m==h) cout<<"YES\n";
                else if (oglinda() || consecutive() || putere(h*100+m)) cout<<"YES\n";
                else cout<<"NO\n";
        }
        else cout<<"NO\n";
    }
    return 0;
}