judge = {"WA":1, "TLE":2, "MLE":3, "OLE":4, "RE":5} n = int(input()) ans = ["No"]*n for i in range(n): 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[i] = "Yes" print(*ans,sep="\n")