class Solver
  attr_accessor :a, :n, :k, :l, :r
  def initialize
    @n = gets.to_s.to_i
    @a = Array.new(n){ gets.to_s.split.map{ |v| v.to_i } }
  end

  def solve
    lo = []
    hi = []
    a.each do |v|
      k,l,r = v
      l > r ? lo << v : hi << v
    end
    lo.sort!
    hi.sort!
    happy = 0
    (lo+hi).each_with_index do |v,i|
      k,l,r = v
      happy += i < k ? l : r
    end
    happy
  end
end

class Problem
  attr_accessor :t, :a, :b, :n, :x, :m, :h, :w, :dp

  def initialize
    @t = gets.to_s.to_i
  end

  def solve
    t.times.with_object([]) do |i,ans|
      ans << Solver.new.solve
    end
  end

  def show(ans)
    puts ans.join("\n")
  end
end

Problem.new.instance_eval do
  show(solve)
end
