#include <iostream>
#include <fstream>
using namespace std;
//ifstream f("peculiar.in");
//ofstream g("peculiar.out");
char s[5];

int solve()
{
    cin>>s[0]>>s[1]>>s[2]>>s[3]>>s[4];;
    int x=s[0]-'0';
    int y=s[1]-'0';
    int z=s[3]-'0';
    int t=s[4]-'0';
    int xy=x*10+y;
    int zt=z*10+t;
    int tz=t*10+z;

    if (xy<0||xy>=24) return 0;
    if (zt<0||zt>=60) return 0;

    if (zt==0) return 1;
    if (xy==zt) return 1;
    if (xy==tz) return 1;
    if (y==x+1&&z==y+1&&t==z+1) return 1;
    if (z==t+1&&y==z+1&&x==y+1) return 1;
    return 0;



}


int main()
{
    int n;
    cin>>n;
    while (n) {
        if (solve()==1)
            cout<<"YES\n";
        else
            cout<<"NO\n";
        n--;
    }
    return 0;
}