#include <iostream>
using namespace std;

bool hok(char*h){
	return ((((h[0]-'0')*10+(h[1]-'0'))<24)&&(((h[3]-'0')*10+(h[4]-'0'))<60));
}
bool t1(char*h){
	return (h[3]==0&&h[4]==0);
}
bool t2(char*h){
	return(h[0]==h[3]&&h[1]==h[4]);
}
bool t3(char*h){
	return(h[0]==h[4]&&h[1]==h[3]);
}
bool t4(char*h){
	return((h[0]==(h[1]-1))&&(h[1]==(h[3]-1))&&(h[3]==(h[4]-1)));
}
bool t5(char*h){
	int n=(h[0]-'0')*1000+(h[1]-'0')*100+(h[3]-'0')*10+(h[4]-'0');
	if(n>=1024&&!(n&(n-1))){
		return true;
	}
	else{
		return false;
	}
}

int main(){
	int N;
	char h[6];
	cin>>N;cin.clear();cin.ignore();
	for(int i=0;i<N;++i){
		cin.getline(h,6,'\n');
		if(hok(h)){
			if (t1(h)){cout<<"YES"<<endl;}
			else{
				if(t2(h)){cout<<"YES"<<endl;}
				else{
					if(t3(h)){cout<<"YES"<<endl;}
					else{
						if(t4(h)){cout<<"YES"<<endl;}
						else{
							if(t5(h)){cout<<"YES"<<endl;}
							else{
							cout<<"NO"<<endl;
							}
						}
					}
				}
			}
		}
		else{
			cout<<"NO"<<endl;
		}
	}
	return 0;
}