#include using namespace std; int main() { int n, i, a, b, c, d, nr, ind, v[51]; char x, y, z, t, s, enter; scanf("%d", &n); for(i = 0; i < n; i++) { scanf("%c%c%c%c%c%c", &enter, &x, &y, &s, &z, &t); a = x - '0'; b = y - '0'; c = z - '0'; d = t - '0'; ind = 0; nr = 1000 * a + 100 * b + 10 * c + d; while(nr > 0) { if(nr % 2) ind = 1; nr /= 2; } if(10 * a + b < 24 && 10 * c + d < 61) { if((c == 0 && d == 0) || (10 * a + b == 10 * c + d) || (10 * a + b == c + 10 * d) || (b == a + 1 && c == b + 1 && d == c + 1)) v[i] = 1; else if(ind == 0) v[i] = 1; else v[i] = 0; } else v[i] = 0; } for(i = 0; i < n; i++) { if(v[i] == 1) printf("YES\n"); else printf("NO\n"); } return 0; }