#include<iostream>
#include<string>
#include<stdio.h>
#include<math.h>
using namespace std;
int pp(int n)
{for(int i=1;i<=13;i++)
	{if(pow(2.0,i)==n)
		return 1;}
return 0;
	
}
int main()
{
	int n;
	cin>>n;
	char s[256][256];
	int a[50],b[50],i;
	for(i=0;i<=n;i++)
	{	gets(s[i]);
	}	
	int j=0;
	for(i=0;i<=n;i++)
	{
		a[i]=(s[i][j]-'0')*10+(s[i][j+1]-'0');
		b[i]=(s[i][j+3]-'0')*10+(s[i][j+4]-'0');
		
	}
	for(i=1;i<=n;i++)
	{
		if(a[i]>=0&&a[i]<24&&b[i]>=0&&b[i]<60)
		{if(b[i]==0)
			cout<<"YES"<<endl;
		else if(a[i]==b[i])
			cout<<"YES"<<endl;
		else if(a[i]==b[i]%10*10+b[i]/10)
			cout<<"YES"<<endl;
		else if(a[i]/10==b[i]/10-2&&a[i]%10==b[i]%10-2)
			cout<<"YES"<<endl;
		else if (pp(a[i]*100+b[i]))
			cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		}
		else cout<<"NO"<<endl;
		
	}
	
}