#include <iostream>
#include <fstream>
#include <cstring>
#include <cmath>

using namespace std;

ifstream f ("input.in");

int n;
char s[10];

bool parseaza(char s[], int &h, int &m) {
    int i = 0, l = strlen(s);
    h = m = 0;
    if (!('0' <= s[0] && s[0] <= '9')) return false;
    while(i < l && s[i] != ':') {
        h = h * 10 + s[i] - '0';
        i++;
    }
    if (s[i] != ':') return false;
    i++;
    while(i < l) {
        m = m * 10 + s[i] - '0';
        i++;
    }
    if (h > 24) return false;
    if (m > 60) return false;
    return true;
}

void rezolva(int h, int m) {
    /*
    It is an exact hour: ZT == "00" (e.g. 12:00)
It is a doubled time: XY == ZT (e.g. 12:12)
It is a mirror time: XY == TZ (e.g. 12:21)
It has consecutive digits (e.g. 01:23, 23:45)
After removing the separating ":", the remaining 4-digit number is a power of two with no leading zeros (e.g. 10:24, 20:48)
*/
    if (m == 0 || h == m) {cout << "YES"; return;}
    if (h / 10 + 1 == h % 10 && h % 10 + 1 == m / 10 && m / 10 + 1 == m % 10) {cout << "YES"; return;}
    if (h / 10 == m % 10 && h % 10 == m / 10) {cout << "YES"; return;}
    int a = 100 * h + m;
    if (a == 2048 || a == 1024) {cout << "YES"; return;}
    cout <<  "NO";
}

int main() {
    cin >> n;
    int h, m;
    bool ok;
    cin.getline(s, 10);
    for (int i = 1; i <= n; i++) {
        cin.getline(s, 10);
        ok = parseaza(s, h, m);
        if (ok) rezolva(h, m);
        else cout << "NO";
        cout << '\n';
    }
}