N = gets.to_i N.times do a, w, t, m, o, r = gets.split.map(&:to_i) a2, w2, t2, m2, o2, r2 = gets.split.map(&:to_i) x = gets.chomp flg = true case x when 'WA' flg = false if w != 0 flg = false if [a2, t2, m2, o2, r2].any? { |v| v != 0 } when 'TLE' flg = false if t != 0 flg = false if [a2, w2, m2, o2, r2].any? { |v| v != 0 } when 'MLE' flg = false if m != 0 flg = false if [a2, w2, t2, o2, r2].any? { |v| v != 0 } when 'OLE' flg = false if o != 0 flg = false if [a2, w2, m2, t2, r2].any? { |v| v != 0 } when 'RE' flg = false if r != 0 flg = false if [a2, w2, m2, o2, t2].any? { |v| v != 0 } end if flg puts 'Yes' else puts 'No' end end