def solve(): awt = list(map(int, input().split())) awt2 = list(map(int, input().split())) x = input() pos = " WTMOR".index(x[0]) if awt2[0] > awt[0] or awt[pos] != 0: print("No") return for i in range(1, 6): if pos == i: continue if awt2[i] != 0: print("No") return print("Yes") for _ in range(int(input())): solve()