import sys sys.setrecursionlimit(10**7) def I(): return int(sys.stdin.readline().rstrip()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LI2(): return list(map(int,sys.stdin.readline().rstrip())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def LS2(): return list(sys.stdin.readline().rstrip()) N = I() d = {'WA':1,'TLE':2,'MLE':3,'OLE':4,'RE':5} for _ in range(N): A0 = LI() A1 = LI() r = d[S()] for i in range(1,6): if (i == r and A0[i] > 0) or (i != r and A1[i] > 0): print('No') break else: print('Yes')