#include using namespace std; typedef int PTIME[4]; enum {X, Y, Z, T}; bool ValidHour(PTIME t){ int h = t[X] * 10 + t[Y]; return 0 <= h && h < 24; } bool ValidMinute(PTIME t){ int m = t[Z] * 10 + t[T]; return 0 <= m && m < 60; } bool ValidPTIME(PTIME t){ return ValidHour(t) && ValidMinute(t); } bool ExactHour(PTIME t){ return t[Z] == 0 && t[T] == 0; } bool DoubledPTIME(PTIME t){ return t[X] == t[Z] && t[Y] == t[T]; } bool MirrorPTIME(PTIME t){ return t[X] == t[T] && t[Y] == t[Z]; } bool ConsecutivePTIME(PTIME t){ return t[Y] == t[X] + 1 && t[Z] == t[Y] + 1 && t[T] == t[Z] + 1; } bool PowerOfTwo(PTIME 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]; PTIME 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 (ValidPTIME(t) && (ExactHour(t) || DoubledPTIME(t) || MirrorPTIME(t) || ConsecutivePTIME(t) || PowerOfTwo(t))) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }