#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;

    while (n--)
    {
        char x, y, s, z, t;
        cin >> x >> y >> s >> z >> t;

        if (10 * (x - '0') + (y - '0') < 24 &&
            10 * (z - '0') + (t - '0') < 60 &&
            (z == '0' && t == '0' ||
            x == z && y == t ||
            x == t && y == z ||
            y == x + 1 && z == y + 1 && t == z + 1 ||
            x == '1' && y == '0' && z == '2' && t == '4' ||
            x == '2' && y == '0' && z == '4' && t == '8'))
            cout << "YES\n";
        else
            cout << "NO\n";
    }
}