#include<iostream>
using namespace std;
int x,y,z,t,i,n,nr;
char ora[6];
int main()
{
    cin>>n;
    for(i=1;i<=n;i++){
        cin>>ora;
        x=ora[0]-'0';
        y=ora[1]-'0';
        z=ora[3]-'0';
        t=ora[4]-'0';
        if(x>2 || y>4 || z>6 || z==6 && t!=0)
        cout<<"NO";
        else
        if(z==0 && t==0)
            cout<<"YES";
        else
        if(x==z&& y==t)
            cout<<"YES";
        else
        if(x==t && y==z)
            cout<<"YES";
        else
        if(y==x+1 && z==y+1 && t==z+1)
            cout<<"YES";
        else{
        nr=x*1000+y*100+z*10+t;
        while(nr%2==0){//cout<<nr<<' ';
            nr/=2;
        }
        if(nr==1 && t!=1)
            cout<<"YES";
        else
        cout<<"NO";
        cout<<endl;
        }
    }
    return 0;
}