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

toInts :: String -> [Int]
toInts = map read . words

main = do
 t <- read <$> getLine
 sequence_ . replicate t $ do
  [n,k] <- toInts <$> getLine
  xs <- toInts <$> getLine
  print . sum . drop (k-1) . reverse . sort . makeDiff $ xs

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