#include using namespace std; int n,i,x; char l[20]; int main() { cin>>n; cin.get(); for (i=1;i<=n;i++) { cin.getline(l,10); if (l[0]>'2'||(l[0]=='2'&&l[1]>'3')||l[3]>'5') { cout<<"NO\n"; continue; } x=(l[0]-'0')*10+l[1]-'0'; x=x*10+l[3]-'0'; x=x*10+l[4]-'0'; if ((l[3]=='0'&&l[4]=='0')||(l[0]==l[3]&&l[1]==l[4])||(l[0]==l[4]&&l[1]==l[3])||(l[1]==l[0]+1&&l[3]==l[1]+1&&l[4]==l[3]+1)||(l[0]!='0'&&!x&(x-1))) cout<<"YES\n"; else cout<<"NO\n"; } return 0; }