judge = {'WA':1, 'TLE':2, 'MLE':3, 'OLE':4, 'RE':5} T = int(input()) ans = ['No']*T for t in range(T): A = list(map(int, input().split())) B = list(map(int, input().split())) X = input() if A[judge[X]]==0 and sum(B[1:])-B[judge[X]]==0: ans[t] = 'Yes' print(*ans, sep='\n')