fun main(args:Array<String>):Unit {
    repeat(readLine()!!.toInt()){
        val (n, k) = readLine()!!.split(' ').map(String::toInt)
        val homes = readLine()!!.split(' ').map(String::toLong)
        println(homes.last() - homes.first() - (1 until n).map{
            homes[it] - homes[it - 1]
        }.sortedDescending().take(k - 1).sum())
    }
}
