#include <cstdio>

using namespace std;
int b[8],q,n,i;
char x,y,z,t,a;
bool ok;
int main()
{
    freopen ("p1.in","r",stdin);
    freopen ("p1.out","w",stdout);
    scanf ("%d\n", &n);
    for (i=1;i<=n;i++)
    {
        scanf ("%c%c%c%c%c\n", &x, &y, &a, &z, &t);
        b[1]=x-'0';
        b[2]=y-'0';
        b[3]=z-'0';
        b[4]=t-'0';
        if ((b[1]*10+b[2])<24 && (b[3]*10+b[4])<60)
        {
        if (b[3]==0 && b[4]==0)
            printf ("YES\n");
        else if (b[1]==b[3] && b[2]==b[4])
            printf ("YES\n");
        else if (b[1]==b[4] && b[3]==b[2])
            printf ("YES\n");
        else if (b[1]+1==b[2] && b[2]+1==b[3] && b[3]+1==b[4])
            printf ("YES\n");
        else if (b[1]!=0)
        {
            q=b[1];
            q=q*10+b[2];
            q=q*10+b[3];
            q=q*10+b[4];
            if (q>1)
            ok=true;
            else
                ok=false;
            while (q>1)
            {
                if (q%2!=0)
                {
                    ok=false;
                    break;
                }
                q/=2;
            }
            if (ok==true)
                printf ("YES\n");
            else
                printf ("NO\n");
        }
        else
            printf ("NO\n");
        }
        else
            printf ("NO\n");
    }
    return 0;
}