#include #include using namespace std; int t, i, a,b,c, d , n; string s; bool pow(int n) { return (n & (n-1) ) == 0; } int main() { cin >> t; for (i=1; i<=t;i++) { cin >> s; a=s[0]-'0';b=s[1]-'0'; c=s[3]-'0';d=s[4]-'0'; if (a*10+b >= 24 || c*10+d >=60 ) { cout << "NO\n"; continue; } if (c*10+d==0 || a*10+b==c*10+d || a*10+b == d*10+c || (a+1==b && b+1==c && c+1==d) || (pow(a*1000+b*100+c*10+d) && a)) cout << "YES"; else cout <<"NO"; cout << "\n"; } return 0; }