#include <iostream>
#include <string>

using namespace std;

int checkTime(string time)
{
	if (time[3] == '0' && time[4] == '0')
	{
		return 1;
	}
	
	if (time[0] == time[3] && time[1] == time[4])
	{
		return 1;
	}
	
	if (time[0] == time[4] && time[1] == time[3])
	{
		return 1;
	}
	
	if (time[1] == time[0] + 1 && time[3] == time[1] + 1 && time[4] == time[3] + 1)
	{
		return 1;
	}
	
	if (time == "10:24" || time == "20:48")
	{
		return 1;
	}
	
	return 0;
}

int main()
{
	int n;
	string time;
	
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		getline(cin, time);
		if (checkTime(time))
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	
	return 0;
}