gets.to_i.times do
  n, k = gets.split.map(&:to_i)
  homes = gets.split.map(&:to_i)

  if homes.size <= k
    puts 0 
    next
  end

  if k == 1
    puts homes.last - homes.first
    next
  end

  diff = homes.each_cons(2).map do |l, r|
    r - l
  end


  minus = diff.sort.reverse[0..(k-2)].inject(:+)
  puts homes.last - homes.first - minus
end