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 if take.size >= 3 while take[2] > 0 answer += 1 take[0] -= 1 take[1] -= 1 take[2] -= 1 take = take.sort.reverse end end puts answer end end end Yukicoder.new