#include <iostream>
#include <fstream>
#include <string>
#include <queue>
#include <cstring>
#include <iomanip>
#include <stack>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

bool solve()
{

    char x,y,z,t,d;
    cin>>x>>y>>d>>z>>t;
    if((x-'0')*10 +(y-'0') >= 24)
        return false;
    if((z-'0')*10 +(t-'0') >= 60)
        return false;
    if(z == '0' && t == '0')
        return true;
    if(x == z && y == t)
        return true;
    if(x == t && y == z)
        return true;
    if(x + 1 == y && y + 1 == z && z + 1 == t)
        return true;
    int n = (x-'0')*1000+(y-'0')*100 + (z-'0')*10 + t - '0';
    if(n == 1024 || n == 2048)
        return true;
    return false;

}

int main()
{
    int t;
    cin>>t;
    for(int i = 1; i<=t; i++)
        if(solve())
            cout<<"YES\n";
        else cout<<"NO\n";
    return 0;
}