#include char x[10]; int main() { int n; scanf("%d\n", &n); for (int i = 1; i <= n; ++i) { gets(x + 1); bool ok = false; if (x[4] == '0' && x[5] == '0') ok = 1; if (x[1] == x[4] && x[2] == x[5]) ok = 1; if (x[1] == x[5] && x[2] == x[4]) ok = 1; bool ok2 = 1; char prev = x[1]; for (int i = 2; i <= 5; ++i) if (i != 3) { if (x[i] != prev + 1) ok2 = 0; prev = x[i]; } if (ok2 == 1) ok = 1; int xx = (x[1] - '0') * 10 + x[2] - '0'; int yy = (x[4] - '0') * 10 + x[5] - '0'; ok2 = 0; if (0 <= xx && xx < 24) if (0 <= yy && yy < 60) ok2 = 1; if (ok2 == 0) ok = 0; printf("%s\n", ok ? "YES" : "NO"); } return 0; }