#include #include #include #include #include #include using namespace std; char s1[100] ; char s2[100] ; int n ; bool verif ( const char* s1 , const char* s2){ stringstream ss ; ss << s1 ; int x ; ss >> x ; ss.clear(); ss << s2 ; int y ; ss >> y ; bool ok = true ; if ( x < 0 || x >= 24 || y < 0 || y >= 60) ok = false; return(ok); } bool pow2 (const char* s1 , const char* s2){ stringstream ss ; ss << s1 ; int x ; ss >> x ; ss.clear(); ss << s2 ; int y ; ss >> y ; if (x == 10 && y == 24) return(true); if (x == 20 && y == 48) return(true); return(false); } int main(){ //freopen("a.in","r",stdin) ; cin >> n ; cin.get(); while(n--) { cin.getline(s1,100,':') ; cin.getline(s2,100) ; if (strlen(s1) == 2 && strlen(s2) == 2) { if(verif(s1,s2) == false){ cout << "NO\n" ; continue ; } bool ok = false ; if(s1[0] == s2[0] && s1[1] == s2[1]) ok = true; else if ( s2[0] == '0' && s2[1] == '0') ok = true; else if(s1[0] == s2[1] && s1[1] == s2[0]) ok = true; else if(s1[0]-'0'==s1[1]-'0'+1 && s1[1]-'0'==s2[0]-'0'+1 && s2[0]-'0'==s2[1]-'0'+1) ok = true ; else if(pow2(s1,s2)) ok = true ; if(ok)cout << "YES\n" ; else cout << "NO\n" ; }else{ cout << "NO\n"; } } return (0); }