#include <iostream>

using namespace std;

int inv(int x)
{
    int y=0;
    while (x>0)
    {
        y=y*10+x%10;
        x=x/10;
    }
    return y;
}

int consec(int x,int y)
{
    if(x/10==x%10-1 && x%10-1==y/10-2 && y/10-2 == y%10-3)
        return 1;
    else return 0;
}

int power2(int x,int y)
{
    x=x*100+y;
    if(x==1024)
        return 1;
    if (x==2048)
        return 1;
    if(x==512)
        return 1;
    if(x==256)
        return 1;
    if(x==128)return 1;
    if(x==64)return 1;
    if(x==32)return 1;
    if(x==16)return 1;
    if(x==8)return 1;
    if(x==4)return 1;
    if(x==2)return 1;

    return 0;

}

int read(int &x,int &y)
{
    char s[5];
    cin>>s;
    x=s[0]-'0';
    x=x*10+s[1]-'0';
    y=s[3]-'0';
    y=y*10+s[4]-'0';
}

int main()
{
    int n,x,y;
    char c;
    int ok=1;
    cin>>n;
    for (int i=1; i<=n; ++i)
    {
        read(x,y);
        if (x<0 || x>23)
            ok=0;
        if(y<0 || y>59)
            ok=0;
        if(x!=y && x!=inv(y) && consec(x,y)==0 && power2(x,y)==0)
            ok=0;
        if(ok==0)
            cout<<"NO";
        else
            cout<<"YES";
    }
    return 0;
}