import sys def resolve(): inp = str1d() n = int(inp[0]) error = {'WA':0,'TLE':1,'MLE':2,'OLE':3,'RE':4} for i in range(n): a0, *error0 = map(int,inp[3*i+1].split()) a1, *error1 = map(int,inp[3*i+2].split()) x=inp[3*i+3] errorid = error[x] if error0[errorid] > 0: print('No') continue errorcase0 = sum(error0) othererror1 = sum([error1[i] for i in range(5) if i != errorid]) if errorcase0<=error1[errorid] and othererror1 == 0: print('Yes') else: print('No') def str1d():return sys.stdin.read().splitlines() resolve()