mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline dic = {"WA": 1, "TLE": 2, "MLE": 3, "OLE": 4, "RE": 5} for _ in range(int(input())): A = list(map(int, input().split())) B = list(map(int, input().split())) i = dic[input().rstrip('\n')] ok = 1 if A[i] != 0: ok = 0 for j in range(1, 6): if i == j: continue if B[j] != 0: ok = 0 if ok: print("Yes") else: print("No") if __name__ == '__main__': main()