#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <algorithm>

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
using namespace std;

const int INF = 0x3f3f3f3f;
const double EPS = 0.000000001;
const double PI = 3.141592653589793;
const long long LLINF = 99999999999999999LL;
const int MAX_N = 100002;
const int MOD = 1000000007;

int N, M, K;
int v[MAX_N];

int main()
{
    /*
    #ifndef ONLINE_JUDGE
        freopen("data.in", "r", stdin);
    #endif
    */

    int T;
    cin >> T;

    char c;
    for(int t = 1; t <= T; ++t) {
        cin >> N;
        cin >> c;
        cin >> M;

        if(N >= 24 || M >= 60) {
            cout << "NO\n";
            continue;
        }

        int m = (M % 10) * 10 + M / 10, ok = 0;

        if(M == 0)
            ok = 1;

        if(N == M)
            ok = 1;

        if(N == m)
            ok = 1;

        v[1] = N / 10;
        v[2] = N % 10;
        v[3] = M / 10;
        v[4] = M % 10;

        if(v[2] == v[1] + 1 && v[3] == v[2] + 1 && v[4] == v[3] + 1)
            ok = 1;

        if(v[1] > 0) {
            int x = N * 100 + M;

            for(int i = 1; i <= 15; ++i)
                if((1 << i) == x)
                    ok = 1;
        }

        if(ok)
            cout << "YES\n";
        else cout << "NO\n";
    }

    return 0;
}