#include using namespace std; typedef int time[4]; enum {X, Y, Z, T}; bool ValidHour(time t){ int h = t[X] * 10 + t[Y]; return 0 <= h && h < 24; } bool ValidMinute(time t){ int m = t[X] * 10 + t[Y]; return 0 <= m && m < 60; } bool ValidTime(time t){ return ValidHour(t) && ValidMinute(t); } bool ExactHour(time t){ return t[Z] == 0 && t[T] == 0; } bool DoubledTime(time t){ return t[X] == t[Z] && t[Y] == t[T]; } bool MirrorTime(time t){ return t[X] == t[T] && t[Y] == t[Z]; } bool ConsecutiveTime(time t){ return t[Y] == t[X] + 1 && t[Z] == t[Y] + 1 && t[T] == t[Z] + 1; } bool PowerOfTwo(time t){ int num = t[X] * 1000 + t[Y] * 100 + t[Z] * 10 + t[T]; if (t[X] == 0) return false; return !(num & (num - 1)); } int main(){ int n; cin >> n; char line[10]; time t; for (int i = 0; i < n; i++){ cin >> line; t[0] = line[0] - '0'; t[1] = line[1] - '0'; t[2] = line[3] - '0'; t[3] = line[4] - '0'; if (ValidTime(t) && (ExactHour(t) || DoubledTime(t) || MirrorTime(t) || ConsecutiveTime(t) || PowerOfTwo(t))) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }