#include using namespace std; bool a[64]; int main () { int n; cin >> n; for (int i = 1; i <= n; ++i) { char xxx, yyy, zzz, ttt, h; cin >> xxx >> yyy >> h >> zzz >> ttt; int x, y, z, t, xx, yy, zz, tt; x = xx = xxx - 48; y = yy = yyy - 48; z = zz = zzz - 48; t = tt = ttt - 48; if (!(xx * 10 + yy < 24 && zz * 10 + tt < 60)) { a[i] = false; continue; } xx = xx * 1000 + yy * 100 + zz * 10 + tt; if (!z && !t) a[i] = true; else if (x == z && y == t) a[i] = true; else if (x == t && y == z) a[i] = true; else if (t == z + 1 && z == y + 1 && y == x + 1) a[i] = true; else if (xx == 1024 || xx == 2048) a[i] = true; else a[i] = false; } for (int i = 1; i <= n; ++i) if (a[i]) cout << "YES\n"; else cout << "NO\n"; return 0; }