#include <iostream>
using namespace std;

int power(int a)
{
	int c = 1;

	while (c < a)
	{
		c = c * 2;
	}
	if (c == a && c != 1) return 1;
	return 0;
}

int main()
{
	int n,i,a1,b1,c1,d1;
	char a, b, c, d, e;
	cin >> n;

	int first, second;
	for (i = 1; i <= n; i++)
	{
		cin >> a >> b >> c >> d >> e;
		first = (a - '0') * 10 + (b - '0');
		second = (d - '0') * 10 + (e - '0');

		a1 = a - '0';
		b1 = b - '0';
		c1 = d - '0';
		d1 = e - '0';

		int nr = first * 100 + second;

		if (a1 > 2 || a1 == 2 && b1 > 4 || c1 == 6 && d1 > 0 || c1>6) cout << "NO\n";
		else if (b1 - a1 == 1 && c1 - b1 == 1 && d1 - c1 == 1 || first == second || a1 == d1 && b1 == c1 || second == 0 || power(nr) == 1) cout << "YES\n";
		else cout << "NO\n";
	}
	return 0;
}