dnum = gets.to_i
output = []
for i in 0..dnum-1
    n,k = gets.split(" ").map(&:to_i)
    x = []
    x << gets.split(" ").map(&:to_i)
    xd = []
    for i in 0..n-2
        xd << x[0][i+1] - x[0][i]
    end
    print("xd: #{xd}\n")
    xd.sort!
    print("xd.sort!: #{xd}\n")
    sum = 0
    for i in 0..xd.length-k
        sum += xd[i]
    end
    output << sum
end
for i in 0..output.length-1
    print("#{output[i]}\n")
end