#include <iostream>

using namespace std;

int main ( ) {
	char timp [6];
	int n, N;

	cin >> n;
	N = n;

	while ( n ) {
		int ora, minute, ok = 0, da = 0;

		if ( n != N )
			cout << "\n";

		cin >> timp;

		ora = timp [0] - '0';
		ora *= 10;
		ora += timp [1] - '0';

		minute = timp [3] - '0';
		minute *= 10;
		minute += timp [4] - '0';

		if ( ora < 24 && minute < 60 && 0 <= ora && 0 <= minute ) {
			if ( timp [0] == timp [4] && timp [1] == timp [3] ) {
				ok = 1;

				cout << "YES";
			} else {
				if ( timp [0] == timp [1] - 1 && timp [1] == timp [3] - 1 && timp [3] == timp [4] - 1 ){
					ok = 1;

					cout << "YES";
				} else if ( minute == 0 ) {
					ok = 1;

					cout << "YES";
				} else if ( minute == ora ) {
					ok = 1;

					cout << "YES";
				} else {
					int tmp = ora * 100 + minute;
					
					if ( tmp == 1024 || tmp == 2048 || tmp == 4096 || tmp == 8192 ) {
						ok = 1;

						cout << "YES";
					}
				}
			}
		}

		if ( !ok ){
			cout << "NO";
		}

		n--;
	}

	return 0;
}