#include <iostream>
#include <cstring>

using namespace std;

int n;
char s[10], aux[10], hour[10], minute[10];

bool consecutive_digits() {
    char *x = strchr(aux, ':');
    strcpy(x, x+1);

    for(int i = 0; i < 3; i++)
        if(aux[i] != aux[i+1] - 1)
            return false;

    return true;
}

bool verify_peculiar() {
    if(strcmp(minute, "00") == 0)
        return true;
    if(strcmp(hour, minute) == 0)
        return true;
    if(strcmp(hour, strrev(minute)) == 0)
        return true;
    if(consecutive_digits() == true)
        return true;
    if(strcmp(aux, "1024") == 0 || strcmp(aux, "2048") == 0 || strcmp(aux, "4096") == 0 || strcmp(aux, "8192") == 0)
        return true;
    return false;
}

bool validate() {
    if(hour[0] > '2' || hour[0] == '2' && hour[1] > '3')
        return false;
    if(minute[0] > '5')
        return false;
    if(verify_peculiar() == false)
        return false;
    return true;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> s;
        strcpy(aux, s);
        char *t = strtok(s, ":");
        strcpy(hour, t);
        t = strtok(NULL, ":");
        strcpy(minute, t);

        if(validate() == true)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;

        memset(s, 0, sizeof(s));
        memset(aux, 0, sizeof(aux));
        memset(hour, 0, sizeof(hour));
        memset(minute, 0, sizeof(minute));
    }
    return 0;
}