#include <cstdio>
#include <iostream>
#include <fstream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <ctype.h>
#include <cstring>
#include <string>
#include <ctime>
#include <cassert>
#include <utility>

using namespace std;

bool powerOfT(int h, int m) {
    int n = 0;
    if(h < 10) {
        return false;
    }
    int x, y, z, t;
    y = h % 10;
    h /= 10;
    x = h % 10;

    t = m % 10;
    m /= 10;
    z = m % 10;

    n = x;
    n = n * 10 + y;
    n = n * 10 + z;
    n = n * 10 + t;
    //cout << n << ";;;;;; \n";
    while(n % 2 == 0 && n > 1) {
        n /= 2;
    }
    return n == 1;
}

int main() {
//	freopen("date.in", "r", stdin);
//	freopen("date.out","w", stdout);

    int n;
    char x, y, z, t;
    scanf("%d\n", &n);
    for(int i = 0; i < n; i++) {
        scanf("%c%c:%c%c\n", &x, &y, &z, &t);
        int h = (x - '0') * 10 + (y - '0');
        int m = (z - '0') * 10 + (t - '0');
        //cout << h << m << "\n";
        if(h >= 0 && h < 24 && m >= 0 && m < 60) {
            if(m == 0 || h == m || (x == t && y == z)|| (x == y - 1 && y == z - 1 && z == t - 1) || powerOfT(h, m)) {
                printf("YES\n");
            }
            else {
                printf("NO\n");
            }
        }
        else {
            printf("NO\n");
        }
    }

	return 0;
}