#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <ctime>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#define pii pair <int, int>
#define pdd pair <double, double>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define INF 1000000005
using namespace std;
int tests;
string st;

bool isGood(string &st)
{
	int h = (st[0] - '0') * 10 + st[1] - '0';
	if (h > 24)
		return false;
	int m = (st[3] - '0') * 10 + st[4] - '0';
	if (m >= 60)
		return false;
		
	if (st[3] == st[4] && st[3] == '0')
		return true;
	if (st[0] == st[3] && st[1] == st[4])
		return true;
	if (st[0] == st[4] && st[1] == st[3])
		return true;
	if (st[1] == st[0] + 1 && st[3] == st[1] + 1 && st[4] == st[3] + 1)
		return true;
	if (st[0] != '0')
	{
		int x = h * 100 + m;
		
		if (!(x & (x - 1)))
			return true;
	}
	return false;
}
 
int main()
{
    //~ freopen("input", "r", stdin);
    
    cin >> tests;
    for (int i = 1; i <= tests; i++)
    {
		cin >> st;
		//~ cout << "Read: " << st << endl;
			
		if (isGood(st))
			printf("YES\n");
		else
			printf("NO\n");
	}
    return 0;
}