#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include #define rep(i,n) for(int i=0;i<(n);i++) #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) ((int)(x).size()) #define pb push_back using ll = long long; using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b> Q; while(Q--){ vector a(6),b(6); rep(i,6) cin >> a[i]; rep(i,6) cin >> b[i]; int x; string X; cin >> X; if(X=="WA") x=1; if(X=="TLE") x=2; if(X=="MLE") x=3; if(X=="OLE") x=4; if(X=="RE") x=5; int ok = 1; for(int i=1;i<6;i++){ if(x==i) continue; if(b[i]!=0) ok=0; } if(a[0]