#include <iostream>
#include <string.h>
#include  <sstream>
#include <vector>
using namespace std;
vector <string> toAnswer;
bool consecutive(string resp)
{
    for(int i=0; i<3; i++)
        if(resp[i+1]-resp[i] != 1) return false;
    return true;
}
int isPowerOfTwo (string myString)
{
    stringstream converter(myString);
    int x = 0;
    converter >> x;
    x /= 10;
    return ((x != 0) && ((x & (~x + 1)) == x));
}
bool valid(string numere)
{
    stringstream converter(numere);
    int x = 0;
    converter >> x;
    if ( x/1000> 24) return false;
    x = x % 1000;
    x /= 10;
    if(x > 60) return false;
    return true;

}
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
    {
       string ans;
       cin >> ans;
       toAnswer.push_back(ans);
    }
    for(int i=0;i<n;i++)
    {
        string resp = toAnswer[i];
        char x,y,z,t;
        x = resp[0];
        y = resp[1];
        z = resp[3];
        t = resp[4];

        resp[2] = resp[3];
        resp[3] = resp[4];
        if( !valid(resp)) { cout <<"NO\n";continue;}
        else if(z == '0' && t=='0') cout <<"YES";
        else if(x==z && y == t) cout << "YES";
        else if(x == y && z == t) cout <<"YES";
        else if(x == t && y == z) cout << "YES";
        else if(consecutive(resp)) cout << "YES";
        else if(isPowerOfTwo(resp) && (x != '0' || y !='0')) cout << "YES";
        else cout << "NO";
        cout << "\n";
    }
    return 0;
}