using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new bool[t]; for (var u = 0; u < t; ++u) { var c = NList; var d = NList; var x = ReadLine(); ans[u] = Judge(c, d, x); } WriteLine(string.Join("\n", ans.Select(f => f ? "Yes" : "No"))); } static bool Judge(int[] c, int[] d, string x) { if (x == "AC") { for (var i = 1; i < 6; ++i) if (d[i] > 0) return false; } else { var s = new string[] { "AC", "WA", "TLE", "MLE", "OLE", "RE" }; var j = 0; for (var i = 1; i < 6; ++i) if (x == s[i]) { j = i; break; } for (var i = 1; i < 6; ++i) { if (j == i) { if (c[i] > 0) return false; } else { if (d[i] > 0) return false; } } } return true; } }