import Data.List
import Control.Monad
import Control.Applicative

main :: IO ()
main = do
  t <- readLn :: IO Int
  replicateM_ t $ do
    [n, k] <- map read . words <$> getLine :: IO [Int]
    xs <- map read . words <$> getLine :: IO [Int]
    print $ if n - k <= 0 then 0 else sum $ take (n - k) $ sort $ zipWith (-) (tail xs) xs