#include <iostream>
using namespace std;
int nr=0;;
int exact_hour(string x)
{
    //string s;
    int a,b;
    a=x[3]-'0';
    b=x[4]-'0';
    //s=x.substr(3,2);
    if (a==0 && b==0) return 1;
    else return 0;
}
int double_time(string x)
{
    if (x[0]==x[3] && x[1]==x[4]) return 1;
    else return 0;
}
int mirror_time(string x)
{
    if (x[0]==x[4] && x[1]==x[3]) return 1;
    else return 0;
}
int consecutiv(string x)
{
    int a,b,c,d;
    a=x[0]-'0';
    b=x[1]-'0';
    c=x[3]-'0';
    d=x[4]-'0';
    if (b==a+1 && c==b+1 && d==c+1) return 1;
    else return 0;
}
int putere(string x)
{
    int a,b,c,d;
    a=x[0]-'0';
    b=x[1]-'0';
    c=x[3]-'0';
    d=x[4]-'0';
    nr=1000*a+100*b+10*c+d;
    if (nr>1000)
    {
        while (nr%2==0)
        {
            nr/=2;
        }
        if (nr==1) return 1;
        else return 0;
    }
    else return 0;
}
int main()
{
    string x[100];
    int a,b,c,d,p,q;
    int i,n;
    cin>>n;
    for (i=1;i<=n;i++)
    {
        cin>>x[i];
    }
    //cout<<mirror_time(x[i]);
    for (i=1;i<=n;i++)
    {
        a=x[i][0]-'0';
        b=x[i][1]-'0';
        c=x[i][3]-'0';
        d=x[i][4]-'0';
        p=a*10+b;
        q=c*10+d;
        if(p<61 && q<61)
        {
        if (exact_hour(x[i])==1 || double_time(x[i])==1 || mirror_time(x[i])==1 || consecutiv(x[i])==1 || putere(x[i])==1) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        }
        else cout<<"NO"<<endl;
    }



    return 0;
}