#define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include using namespace std; #define DMAX 2502 int x, y, z, t, n, h, m; char s[6]; bool pw2(long long p){ while (p > 1) if (p % 2) return 0; else p /= 2; return 1; } int main(){ int i; //freopen("test.in", "r", stdin); //freopen("test.out", "w", stdout); scanf("%d", &n); for (int i = 0; i < n; i++){ scanf("%s\n", s); x = s[0] - '0'; y = s[1] - '0'; z = s[3] - '0'; t = s[4] - '0'; h = x * 10 + y; m = z * 10 + t; if (h < 24 && m < 60){ if (h == m) printf("YES\n"); else if (x == t && y == z) printf("YES\n"); else if (m == 0 || h == m) printf("YES\n"); else if (y * 10 + h == z * 10 + t) printf("YES\n"); else if (pw2(h * 100 + m) && h >= 10) printf("YES\n"); else if (x + 3 == t && x + 2 == z && x + 1 == y) printf("YES\n"); else printf("NO\n"); } else printf("NO\n"); } return 0; }