#include char a, b, c, d; inline bool nr () { int n = a - '0'; n = n * 10 + b - '0'; n = n * 10 + c - '0'; n = n * 10 + d - '0'; while (n % 2 == 0) n/= 2; return a != '0' && n == 1; } inline bool bun () { if (c == '0' && d == '0') return true; if (a == c && b == d) return true; if (a == d && b == c) return true; if (b == a + 1 && c == b + 1 && d == c + 1) return true; return nr (); } int main () { //freopen ("date.in", "r", stdin); int t; scanf ("%d\n", &t); while (t--) { scanf ("%c%c:%c%c\n", &a, &b, &c, &d); int x = (a - '0') * 10 + (b - '0'); int y = (c - '0') * 10 + (d - '0'); if (x > 24 || y > 60) { printf ("NO\n"); continue; } if (bun ()) printf ("YES\n"); else printf ("NO\n"); } return 0; }