#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

bool solve(string s) {
    int h = (s[0] - '0') * 10 + (s[1] - '0');
    int m = (s[3] - '0') * 10 + (s[4] - '0');
    if(h >= 24 || m >= 60) {
        return false;
    }
    if(m == 0) {
        return true;
    }
    if(h == m) {
        return true;
    }
    if(s[0] == s[4] && s[1] == s[3]) {
        return true;
    }
    if(s[1] == s[0] + 1 && s[3] == s[1] + 1 && s[4] == s[3] + 1) {
        return true;
    }
    if((!((h * 100 + m) & (h * 100 + m - 1))) && h > 9) {
        return true;
    }
    return false;
}

int main() {
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        string s;
        cin >> s;
        if(solve(s)) {
            cout << "YES\n";
        }
        else {
            cout << "NO\n";
        }
        
    }
}