#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>

#include <cassert>
#include <cstdlib>

using namespace std;

int digits(int x) {
    int ret = 0;
    while (x) {
        x/=10;
        ret++;
    }
    return ret;
}

int main() {
    //assert(freeopen("test.in", "r", stdin) && freopen("test.out", "w", stdout));
    ios::sync_with_stdio(0); 
    int t;
    cin >> t;
    cin.get();
    while (t--) {
        int h, m;
        string s;
        getline(cin, s);
        sscanf(s.c_str(), "%d:%d",&h,&m);
        if (h < 24 && m < 60) {
            int p = (h*10 + m / 10)*10 + m % 10;
            if (m == 0) {
                cout << "YES\n";
            } else
            if (m == h) {
                cout << "YES\n";
            } else  
            if (s[0] == s[4] && s[1] == s[3]) {
                cout << "YES\n";
            }
            else
            if (s[0] == s[1] - 1 && s[3] - 1 == s[1] && s[4] == s[3] + 1) {
                cout << "YES\n";
            } else
            if ((digits(p) == 4 &&(p & (p - 1)) == 0)) {
                cout << "YES\n";
            } else {
                cout << "NO\n";
            }
        } else {
            cout << "NO\n";
        }
    }
    return 0;
}