#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <stack>

#define DIM 10
#define vint vector<int>::iterator
#define pint vector< pair<int, int> >::iterator
#define sint set<int>::iterator
#define infile "test.in"
#define outfile "test.out"

using namespace std;

char s[DIM];

int main() {

	int tests;

	cin >> tests;

	while (tests--) {

		cin >> s;

		int hour = (s[0] - '0') * 10 + s[1] - '0';
		int mint = (s[3] - '0') * 10 + s[4] - '0';

		if (!((0 <= hour) && (hour <= 23) && (0 <= mint) && (mint <= 59))) {

			cout << "NO\n";
			continue;

		}

		if ((hour == 10 && mint == 24) || (hour == 20 && mint == 48)) {

			cout << "YES\n";
			continue;

		}

		if (mint == 0) {

			cout << "YES\n";
			continue;

		}

		if (hour == mint) {

			cout << "YES\n";
			continue;

		}

		if (hour == (mint % 10) * 10 + (mint / 10)) {

			cout << "YES\n";
			continue;

		}

		if (hour % 10 - hour / 10 == 1 && mint / 10 - hour % 10 == 1 && mint % 10 - mint / 10 == 1) {

			cout << "YES\n";
			continue;

		}

		cout << "NO\n";

	}

	return 0;
}

//Trust me, I'm the Doctor!