class Yukicoder def initialize t = gets.to_i t.times do n = gets.to_i l = gets.chomp.split.map(&:to_i) take = Hash.new(0) l.each do |i| take[i] += 1 end take = take.values.sort.reverse answer = 0 while take.size >= 3 && take[2] > 0 answer += take[2] take[0] -= take[2] take[1] -= take[2] take[2] -= take[2] take = take.sort.reverse end puts answer end end end Yukicoder.new