#include #include #include #include #include #include #include #include #define ll long long using namespace std; /* It is an exact hour: ZT == "00" (e.g. 12:00) It is a doubled time: XY == ZT (e.g. 12:12) It is a mirror time: XY == TZ (e.g. 12:21) It has consecutive digits (e.g. 01:23, 23:45) After removing the separating ":", the remaining 4-digit number is a power of two with no leading zeros (e.g. 10:24, 20:48) */ string s; bool ko(char s, char s1){ if(char(int(s) + 1) == s1) return true; return false; } bool isPowerOfTwo(string &s){ int x=0,i; if(s[0] == '0') return false; for(i=0;i<5;++i) if(i != 2) x = (x*10) + (s[i] - '0'); if((x&(x-1)) == 0) return true; return false; } int main(){ #ifndef ONLINE_JUDGE ifstream cin("A.in"); ofstream cout("A.out"); #endif int i,N,ok; cin >> N; for(i=1;i<=N;++i) { cin >> s; //cout << s << '\n'; int hours = 10 * (s[0] - 48) + (s[1] - 48); int minutes = 10 * (s[3] - 48) + (s[4] - 48); if((hours > 23) || minutes > 59) { cout << "NO\n"; continue ; } // ok = 0; // 1 if(s[3] == s[4] && s[4] == 0) ok = 1; // 2 if(s[0] == s[3] && s[1] == s[4]) ok = 1; //3 if(s[0] == s[4] && s[1] == s[3]) ok = 1; //4 if(ko(s[0],s[1]) && ko(s[1],s[3]) && ko(s[3],s[4])) ok = 1; if(isPowerOfTwo(s)) ok = 1; if(ok) cout << "YES\n"; else cout << "NO\n"; } return 0; }