#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("date.in");

char c[6];

bool rez()
{
    if((c[0] - '0') * 10 + c[1] - '0' >=24)
        return 0;
    if((c[3] - '0') * 10 + c[4] - '0' >= 60)
        return 0;
    if(c[3] == '0' && c[4] == '0')
        return 1;
    if(c[0] == c[3] && c[1] == c[4])
        return 1;
    if(c[0] == c[4] && c[1] == c[3])
        return 1;
    if(c[0] == c[1] - 1 && c[3] == c[1] + 1 && c[4] == c[3] + 1)
        return 1;
    int nr = 0;
    nr = (((c[0] - '0') * 10 + c[1] - '0') * 10 + c[3] - '0') * 10 + c[4] - '0';
    if(c[0] == '0')
        return 0;
    if(nr & (nr - 1))
        return 0;
    return 1;
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        cin >> c;
        if(rez())
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}