#include <iostream>
#include <math.h>
using namespace std;
int n,v[1000],contor,power;
char x[5];
int main()
{
    cin>>n;
    for(int i=1;i<=n;++i)
    {
        cin>>x;
        v[1] = int(x[0])-48;
        v[2] = int(x[1])-48;
        v[3] = int(x[3])-48;
        v[4] = int(x[4])-48;
        power = 1;
        if(v[1]!=0)
        {
            for(int j=1;j<23;++j)
            {
                power = power*2;
                if(power == v[1]*1000+v[2]*100+v[3]*10+v[4])break;
            }
        }
        if(v[1]*10+v[2]>=24||v[3]*10+v[4]>=60)cout<<"NO"<<'\n';
        else if(power!=23&&power>=2)cout<<"YES"<<'\n';
        else if(v[3]==0&&v[4]==0)cout<<"YES"<<'\n';
        else if(v[1]==v[3]&&v[2]==v[4])cout<<"YES"<<'\n';
        else if(v[1]==v[4]&&v[2]==v[3])cout<<"YES"<<'\n';
        else if(v[4]==v[3]-1&&v[3]==v[2]-1&&v[2]==v[1]-1)cout<<"YES"<<'\n';
        else if(v[4]==v[3]+1&&v[3]==v[2]+1&&v[2]==v[1]+1)cout<<"YES"<<'\n';
        else cout<<"NO"<<'\n';
    }
    return 0;
}