d = dict(zip(['AC', 'WA', 'TLE', 'MLE', 'OLE', 'RE'], range(6))) for _ in range(int(input())): s = list(map(int, input().split())) ns = list(map(int, input().split())) x = d[input()] ans = ('Yes' if (s[x] == 0 and not any(ns[1:x]) and not any(ns[x+1:])) else 'No') print(ans)