def main(): n = int(input()) for _ in range(n): result0 = list(map(int, input().split())) result1 = list(map(int, input().split())) x = input() i = ['AC', 'WA', 'TLE', 'MLE', 'OLE', 'RE'].index(x) if result0[i] == 0 and all(result1[j] == 0 for j in range(1, 6) if i != j): ans = "Yes" else: ans = "No" print(ans) if __name__ == "__main__": main()