#include <iostream>
#include <string.h>
#include <fstream>
using namespace std;
ifstream f("Input");
ofstream g("Output");
int n;
int test(char x,char y,char z,char t,int &r,int h,int m)
    {int a;
    if(z==t)
        r=1;
    else if(h==m)
        r=1;
    else if(x==z and y==t)
        r=1;
    else if(h/10==h%10-1 and h%10==m/10-1 and m/10==m%10-1)
        r=1;
    else
        {a=100*h+m;
        if(a==1024 or a==2048)
            r=1;
        }
    return r;
    }

int main()
{   int i,h,m,r=0,Z;
    char x,y,z,t,s[10];
    f>>n;
    for(i=1;i<=n;i++)
        {f>>s; Z=0;
        r=0;
        x=s[0];
        y=s[1];
        z=s[3];
        t=s[4];
        h=10*((int)x-48)+((int)y-48);
        m=10*((int)z-48)+((int)t-48);
        if(h>=0 and h<=24)
            if(m>=0 and m<=60)
                {if(test(x,y,z,t,r,h,m)) g<<"YES"<<'\n';
                else g<<"NO"<<'\n';Z=1;
                }
        if(Z==0)    g<<"NO"<<'\n';
        }
    f.close();
    g.close();
    return 0;
}