#include <iostream>
#include <string.h>
#include  <sstream>
using namespace std;
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));
}
int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; i++)
    {
        string resp;
        cin >> resp;
        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(x < '0' || y < '0' || x > '2' || y > '4' || z < '0' || t<'0' || z > '6') { cout <<"NO";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";
    }
    return 0;
}