#include <bits/stdc++.h>

using namespace std;

int N;
string S;

bool isPow(int x) {
	return (x & (x - 1)) == 0;
}

bool f(string S) {
	int x = S[0] - '0';
	int y = S[1] - '0';
	int z = S[3] - '0';
	int t = S[4] - '0';
	int h = x * 10 + y;
	int m = z * 10 + t;
	if (!(h >= 0 && h < 24 && m >= 0 && m < 60)) {
		return false;
	}
	if (z == t && z == 0) {
		return true;
	}
	if (x == z && y == t) {
		return true;
	}
	if (x == t && y == z) {
		return true;
	}
	if (y == x + 1 && z == y + 1 && t == z + 1) {
		return true;
	}
	if (x != 0 && isPow(x * 1000 + y * 100 + z * 10 + t)) {
		return true;
	}
	return false;
}

int main() {
//	freopen("date.in", "r", stdin);
//	freopen("date.out","w", stdout);
	cin.sync_with_stdio(false);
	
	cin >> N;
	while (N--) {
		cin >> S;
		
		if (f(S)) {
			cout << "YES\n";
		}
		else {
			cout << "NO\n";
		}
	}
	
	return 0;
}