N=int(input()) S=['AC','WA','TLE','MLE','OLE','RE'] for i in range(N): A=list(map(int,input().split())) B=list(map(int,input().split())) X=input() Y=0 f=0 for j in range(1,len(A)): if S[j]==X: Y=A[j] Z=0 for j in range(1,len(B)): if S[j]==X: Z=B[j] if max(A)==A[0]: print('Yes') else: if Y: print('No') elif Z==sum(A): print('Yes') else: print('No')