#include using namespace std; int main () { int n; scanf ("%d", &n); for (int i = 1; i <= n; ++i) { char x, y, z, t; scanf ("\n%c%c:%c%c", &x, &y, &z, &t); int xx, yy, zz, tt; xx = x - 48; yy = y - 48; zz = z - 48; tt = t - 48; if (!(xx * 10 + yy < 24 && zz * 10 + tt < 60)) { printf ("NO\n"); continue; } xx = xx * 1000 + yy * 100 + zz * 10 + tt; if (!z && !t) printf ("YES\n"); else if (x == z && y == t) printf ("YES\n"); else if (x == t && y == z) printf ("YES\n"); else if (t == z + 1 && z == y + 1 && y == x + 1) printf ("YES\n"); else if (xx == 1024 || xx == 2048) printf ("YES\n"); else printf ("NO\n"); } return 0; }