#include #include #include using namespace std; ifstream cin("txt.in"); ofstream cout("txt.out"); int n; char h1, h2, sep, m1, m2; string ora, minut; int main() { cin >> n; cin.get(); for ( int i = 0; i < n; ++i ) { cin >> h1 >> h2 >> sep >> m1 >> m2; bool ok = false; if ( m1 == '0' && m2 == '0' ) ok = true; if ( h1 == m1 && h2 == m2 ) ok = true; if ( h1 == m2 && h2 == m1 ) ok = true; if ( h1 == '0' && h2 == '1' && m1 == '2' && m2 == '3' || h1 == '1' && h2 == '2' && m1 == '3' && m2 == '4' || h1 == '2' && h2 == '3' && m1 == '4' && m2 == '5' || h1 == '1' && h2 == '0' && m1 == '2' && m2 == '4' || h1 == '2' && h2 == '0' && m1 == '4' && m2 == '8' ) ok = true; ora.clear(); minut.clear(); ora.push_back(h1); ora.push_back(h2); minut.push_back(m1); minut.push_back(m2); bool v = true; if ( ora < "00" || ora > "24" ) v = false; if ( minut < "00" || minut >= "60" ) v = false; if ( v && ok ) cout << "YES\n"; else cout << "NO\n"; } }