#include #include using namespace std; int n; char h1, h2, sep, m1, m2; 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; bool v = true; if ( h1 < '0' && h2 < '0' || h1 > '2' ) v = false; if ( m1 < '0' && m2 < '0' || m1 > '6' ) v = false; if ( v && ok ) cout << "YES\n"; else cout << "NO\n"; } }