q = io.read("*n") a = {} b = {} t = {} t.WA = 2 t.TLE = 3 t.MLE = 4 t.OLE = 5 t.RE = 6 for iq = 1, q do for i = 1, 6 do a[i] = io.read("*n") end for i = 1, 6 do b[i] = io.read("*n") end io.read() c = io.read() c = t[c] f = true if 0 < a[c] then f = false end for i = 2, 6 do if i ~= c and 0 < b[i] then f = false end end print(f and "Yes" or "No") end