Result = ['AC','WA','TLE','MLE','OLE','RE'] N = int(input()) for _ in range(N): R0 = list(map(int, input().split())) R1 = list(map(int, input().split())) X = input() i = Result.index(X) if R0[i] == 0 and any(R1[1:i]+R1[i+1:]) == False: print('Yes') else: print('No')