#include <bits/stdc++.h>
using namespace std;



int main () {
#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
#endif
	string line;
	int n;
	cin >> n;
	getline(cin, line);

	for(int i = 0; i < n; i++) {
		getline(cin, line);
		char c[5] = {0, 0, 0, 0, 0};
		bool ok = false;
		sscanf(line.c_str(), "%c%c:%c%c", c, c+1, c+2, c+3);

		int xy = (c[0] - '0') * 10 + c[1] - '0';
		int zt = (c[2] - '0') * 10 + c[3] - '0';

		if(!(xy < 24 && xy >= 0 && zt < 60 && zt >= 0)) ok = false;
		else {
			if(c[2] == c[3] && c[2] == '0') ok = true;
			if(c[0] == c[2] && c[1] == c[3]) ok = true;
			if(c[0] == c[3] && c[1] == c[2]) ok = true;
			if(c[0] == c[1] - 1 && c[1] == c[2] - 1 && c[2] == c[3] - 1) ok = true;
			if(!strcmp(c, "1024") ||!strcmp(c, "2048")) ok = true;
		}
		cout << (ok ? "YES" : "NO") << "\n";
	}

	return 0;
}