#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int n,i,j,nr,x,y,ok;
char s[10];

int main()
{
    cin>>n;
    cin.get();
    for(i=1;i<=n;i++)
    {
        cin.get(s,6);
        ok=1;
        y=0;
        x=0;
        for(j=0;j<strlen(s);j++)
        {
            if(s[j]==':') ok=0;
            if(ok=1)
            {
                x=x*10+s[j]-'0';
            }
            else
            {
                y=y*10+s[j]-'0';
            }
        }
        cin.get();
        int r=0;
        if(x>24 or x==0 or y>60 and r==0)
        {
            cout<<"NO"<<'\n';
            r=1;
        }
        if(y==0 and r==0)
        {
            cout<<"YES"<<'\n';
            r=1;
        }
        if(x==y and r==0)
        {
            cout<<"YES"<<'\n';
            r=1;
        }
        if(x%10==y/10 and x/10==y%10 and r==0)
            {
            cout<<"YES"<<'\n';
            r=1;
        }
        if(x/10==x%10+1 and x%10==y/10+1 and y/10==y%10+1 and r==0)
         {
            cout<<"YES"<<'\n';
            r=1;
        }
        if(sqrt(double(x*100+y))==int(sqrt(double(x*100+y))) and r==0)
         {
            cout<<"YES"<<'\n';
            r=1;
        }
        if(r==0) cout<<"NO"<<'\n';
    }
    return 0;
}