#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define dbg(x) (cout<<#x<<" = "<<(x)<<'\n') #ifdef HOME const string inputFile = "input.txt"; const string outputFile = "output.txt"; #else const string problemName = ""; const string inputFile = problemName + ".in"; const string outputFile = problemName + ".out"; #endif typedef long long int lld; typedef pair PII; typedef pair PIL; typedef pair PLI; typedef pair PLL; const int INF = (1LL << 31) - 1; const lld LINF = (1LL << 62) - 1; const int dx[] = {1, 0, -1, 0, 1, -1, 1, -1}; const int dy[] = {0, 1, 0, -1, 1, -1, -1, 1}; const int MOD = (int)(1e9) + 7; const int NMAX = 100000 + 5; const int MMAX = 100000 + 5; const int KMAX = 100000 + 5; const int PMAX = 100000 + 5; const int LMAX = 100000 + 5; const int VMAX = 100000 + 5; int bla(int a, int b, int c, int d) { if(a * 10 + b >= 0 && a * 10 + b < 24 && c * 10 + d >= 0 && c * 10 + d < 60) { if(c == 0 && d == 0) return 1; if(a == c && b == d) return 1; if(a == d && b == c) return 1; if((a + 1) % 10 == b && (b + 1) % 10 == c && (c + 1) % 10 == d) return 1; int x = a * 1000 + b * 100 + c * 10 + d; if(x & (-x) == x) return 1; } return 0; } int main() { int N, a, b, c, d; char S[10]; #ifndef ONLINE_JUDGE freopen(inputFile.c_str(), "r", stdin); freopen(outputFile.c_str(), "w", stdout); #endif scanf("%d", &N); while(N--) { scanf("%s", S); a = S[0] - '0'; b = S[1] - '0'; c = S[3] - '0'; d = S[4] - '0'; printf("%s\n", bla(a, b, c, d) ? "YES" : "NO"); } return 0; }