#include using namespace std; using LL=long long; using ULL=unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) string A[]={"AC","WA","TLE","MLE","OLE","RE"}; bool loop(){ int C[6][2]; rep(d,2) rep(i,6) cin>>C[i][d]; string S; cin>>S; bool ok=true; int sum=0; rep(i,6) sum+=C[i][1]; int p=0; rep(i,6) if(A[i]==S) p=i; if(C[p][0]!=0) return false; for(int i=1; i<6; i++) if(A[i]!=S) if(C[i][1]!=0) return false; return true; } int main(){ int T; cin>>T; while(T--) cout<<(loop()?"Yes":"No")<