status = %w[AC WA TLE MLE OLE RE] gets.to_i.times do a = gets.split.map(&:to_i) b = gets.split.map(&:to_i) s = gets.chomp s_i = status.index(s) if (0...6).reject { |i| i == 0 || i == s_i }.all? { |i| b[i] == 0 } wrong_sum = a[1..].sum if a[0] >= b[0] && (a[0] - b[0] + wrong_sum) == b[s_i] puts "Yes" else puts "No" end else puts 'No' end end