#include <iostream>
#include <string>
using namespace std;

bool isPT(string s);

int main()
{
	unsigned int n;
	cin >> n;
	for (unsigned int i = 0; i < n; i++)
	{
		string s;
		cin >> s;
		if (isPT(s))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
}

bool isPT(string s)
{
	string s0 = "";
	s0 += s[0];
	s0 += s[1];
	int x = stoi(s0);
	if ((x < 0) || (x>23))
		return 0;
	s0 = "";
	s0 += s[3];
	s0 += s[4];
	x = stoi(s0);
	if ((x < 0) || (x>59))
		return 0;

	if ((s[3] == '0') && (s[4] == '0'))
		return 1;
	if ((s[0] == s[3]) && (s[1] == s[4]))
		return 1;
	if ((s[0] == s[4]) && (s[1] == s[3]))
		return 1;
	if ((s[0] + 1 == s[1]) && (s[1] + 1 == s[3]) && (s[3] + 1 == s[4]))
		return 1;
	s.erase(s.begin() + 2);
	x = stoi(s);
	int j = 2;
	do
	{
		if (j == x)
			return 1;
		j *= 2;
	} while (j <= x);
	return 0;
}