#include <iostream>
#include <string.h>
#include <stdlib.h>


using namespace std;

int main()
{
    int x,n,i,j,q,p,ok,k;
    char v[10],*a,b[10],*c,*d;


    cin>>n;
    for(i=1;i<=n;i++)
    {
        ok=0;
        cin>>v;
        a=v;
        a+=3;
        strncpy(b,v,2);
        b[2]='\0';
        c=b;
        p=atoi(c);
        q=atoi(a);
        j=q%10*10+q/10;
        x=p%10*10+p/10;
        k=p*10+q;
        while(k)
        {
            if(k%2!=0)
            {
                ok=1;
                break;
            }
            k/=2;
        }
        if( (q==0 || p==q || p==j || q==x || (p/10+1==p%10 && p%10+1==q/10 && q/10+1==q%10) || ok==0) && (p<=24 && q<=60) )
            cout<<"YES";
        else
            cout<<"NO";
    }


    return 0;
}