#include using namespace std; bool Pelicular(char x, char y, char z, char t) { if(z == '0' && t == '0') return true; if(x == z && y==t) return true; if(x==t && y==z) return true; if(x=='1' && y=='2' && z== '3' && t=='4') return true; if(x=='0' && y=='1' && z== '2' && t=='3') return true; if(x=='2' && y=='3' && z== '4' && t=='5') return true; if(x=='1' && y=='0' && z== '2' && t=='4') return true; if(x=='2' && y=='0' && z== '4' && t=='8') return true; return false; } int main() { char x, y , z, t, d; int n; cin>>n; for(int i=1;i<=n;++i) { cin>>x>>y>>d>>z>>t; if(Pelicular(x,y,z,t) == true && (x-'0') * 10 + y-'0' <24 && (z - '0') * 10 + t - '0' < 60) cout<<"YES"; else cout<<"NO"; } return 0; }