#include<bits/stdc++.h>
using namespace std;

bool isIncreasing(int x0, int x1, int x2, int x3) {
  return (x0 + 1 == x1) && (x1 + 1 == x2) && (x2 + 1 == x3);
}

bool isPower2(int x) {
  while (!(x & 1))
    x >>= 1;
  return (x == 1);
}

int main() {
  ifstream cin("input.txt");

  int t;
  cin >> t;

  while (t--) {
    string s;
    cin >> s;

    int h0, h1, m0, m1;
    h0 = s[0] - '0';
    h1 = s[1] - '0';
    m0 = s[3] - '0';
    m1 = s[4] - '0';

    int h = h0 * 10 + h1, m = m0 * 10 + m1;

    if (h < 0 || h >= 24 || m < 0 || m >= 60) {
      cout << "NO\n";
    } else if (m == 0 || h == m || h == m1 * 10 + m0 || isIncreasing(h0, h1, m0, m1) || (h0 > 0 && isPower2(h * 100 + m))) {
      cout << "YES\n";
    } else {
      cout << "NO\n";
    }
  }
}