{-
C++??????????§????
/*
URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2104
?????????: Country Road
????????????: ??¶?????¨??¨????????§????????????????¢?????????????????????¢?????????????????????????¶????????????????
??????????????¨: ?§???????????????????
*/
-}
import Data.List(sort)

read_ :: String -> Int
read_ = read

main = do
 t' <- getLine
 let t = read_ t'
 sequence_ $ replicate t action
 
action = do
 nk <- getLine
 let [n,k] = map read_ . words $ nk
 xs' <- getLine
 print . sum . drop (k-1) . reverse . sort . makeDiff . map read_ . words $ xs'

makeDiff [_] = []
makeDiff (x:y:xs) = (y-x) : makeDiff (y:xs)