gets.to_i.times do
  n,k = gets.chomp.split.map(&:to_i)
  xs = gets.chomp.split.map(&:to_i).sort!
  d = Array.new(n-1) do |i|
    xs[i+1]-xs[i]
  end
  d.sort!.reverse!
  ans = xs[-1]-xs[0]
  p = [k,n].min-1
  if p>0
    ans -= d[0,p].inject(:+)
  end
  puts [ans,0].max
end