def reader(x)
  x.split(" ").map(&:to_i)
end

def solve(xs, n, k)
  edges = {}
  val = xs[-1] - xs[0]
  return val if k == 1 or xs.size < k - 1
  values = xs[0..-2].zip(xs[1..-1])
    .map.with_index { |x, i|
    x[1] - x[0]
  }.sort.reverse[0..k-2]
  val - values.reduce(&:+)
end
data = $stdin.read.split("\n")
data[1..-1].each_slice(2) do |num, items|
  n, k = reader(num)
  xs = reader(items)
  puts solve(xs, n, k)
end