#include<iostream>
#include<cstring>
#include<math.h>
using namespace std;

int main()
{
	char s[6];
	int n, i;
	cin >> n;
	for (i = 1; i <= n; i++)
	{
		cin >> s;
		if (s[0] == s[1] && s[1] == s[3] && s[3] == s[4])
			cout << "YES";
		else
		if (s[0] == s[1] - 1 && s[1] == s[3] - 1 && s[3] == s[4] - 1)
			cout << "YES";
		else
		if (s[0] == s[3] && s[1] == s[4])
			cout << "YES";
		else
		if (s[0] == s[4] && s[1] == s[3])
			cout << "YES";
		else
		{
			int x;
			x = (s[0] - '0') * 1000 + (s[1] - '0') * 100 + (s[3] - '0') * 10 + (s[4] - '0');
			int y = x;
			x = x&(x - 1);
			if (x == 0&&y>=1024)
				cout << "YES";
			else
				cout << "NO";
		}
		cout << "\n";
	}
}