You have $n$ barrels lined up in a row, numbered from left to right from one. Initially, the $i$-th barrel contains $a_i$ liters of water.

You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels $x$ and $y$ (the $x$-th barrel shouldn't be empty) and pour any possible amount of water from barrel $x$ to barrel $y$ (possibly, all water). You may assume that barrels have infinite capacity, so you can pour any amount of water in each of them. 

Calculate the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $k$ times.

Some examples:   if you have four barrels, each containing $5$ liters of water, and $k = 1$, you may pour $5$ liters from the second barrel into the fourth, so the amounts of water in the barrels are $[5, 0, 5, 10]$, and the difference between the maximum and the minimum is $10$;  if all barrels are empty, you can't make any operation, so the difference between the maximum and the minimum amount is still $0$. 


-----Input-----

The first line contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases.

The first line of each test case contains two integers $n$ and $k$ ($1 \le k < n \le 2 \cdot 10^5$) — the number of barrels and the number of pourings you can make.

The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^{9}$), where $a_i$ is the initial amount of water the $i$-th barrel has.

It's guaranteed that the total sum of $n$ over test cases doesn't exceed $2 \cdot 10^5$.


-----Output-----

For each test case, print the maximum possible difference between the maximum and the minimum amount of water in the barrels, if you can pour water at most $k$ times.


-----Example-----
Input
2
4 1
5 5 5 5
3 2
0 0 0

Output
10
0

Difficulty: EASY
Tags: Sorting

Implementation

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
R = lambda : map(int, input().split())
(t,) = R()
exec(t * 'n,k=R();print(sum(sorted(R())[~k:]));')


t = int(input())
for items in range(t):
	(n, k) = map(int, input().split())
	x = sorted(list(map(int, input().split())), reverse=True)[:n]
	m = 0
	for i in range(0, k, 1):
		m += x[i] + x[i + 1]
		x[i] = 0
		x[i + 1] = 0
	print(m)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	i = 1
	s = a[0]
	while k > 0 and i < n:
		s += a[i]
		i += 1
		k -= 1
	print(s)


def solve():
	(n, k) = [int(v) for v in input().split()]
	arr = sorted([int(v) for v in input().split()])
	j = n - 2
	while k > 0 and j >= 0:
		arr[-1] += arr[j]
		arr[j] = 0
		j -= 1
		k -= 1
	print(arr[-1])
t = int(input())
for _ in range(t):
	solve()


import math
import sys
import collections
import bisect
input = sys.stdin.readline
flush = sys.stdout.flush
readint = lambda : int(input())
readintm = lambda : map(int, input().strip().split())
readintl = lambda : list(map(int, input().strip().split()))
readfloatm = lambda : map(float, input().strip().split())
readfloatl = lambda : list(map(float, input().strip().split()))
readstr = lambda : input().strip()
readstrl = lambda : list(input().strip())
join = lambda x, l: x.join(map(str, l))
print = lambda x: sys.stdout.write(str(x))
mod = 1000000007
for _ in range(readint()):
	(n, k) = readintl()
	vals = sorted(readintl(), reverse=True)
	print(sum(vals[:k + 1]))
	print('\n')


import sys
for i in range(int(input())):
	(n, k) = map(int, input().split())
	v = [int(x) for x in input().split()]
	v.sort()
	for i in range(n - 2, -1, -1):
		if k <= 0:
			break
		k -= 1
		v[n - 1] += v[i]
		v[i] = 0
	print(v[n - 1])


def modinv(n, p):
	return pow(n, p - 2, p)

def main():
	for case in range(int(input())):
		(n, k) = [int(x) for x in input().split()]
		arr = [int(x) for x in input().split()]
		arr.sort(reverse=True)
		mx = arr[0]
		for x in arr[1:]:
			if k == 0:
				break
			mx += x
			k -= 1
		print(mx)
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
import os, sys
from io import IOBase, BytesIO
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
while t > 0:
	t -= 1
	s = 0
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	l.sort()
	for i in range(1, k + 2):
		s += l[-i]
	print(s)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	lol = [int(n) for n in input().split()]
	x = max(lol)
	lol.remove(x)
	ran = min(k, len(lol))
	lol.sort(reverse=True)
	x += sum(lol[:ran])
	print(x)


from sys import stdin, stdout
import math, bisect
from collections import Counter, deque, defaultdict
L = lambda : list(map(int, stdin.readline().strip().split()))
M = lambda : map(int, stdin.readline().strip().split())
I = lambda : int(stdin.readline().strip())
S = lambda : stdin.readline().strip()
C = lambda : stdin.readline().strip().split()

def pr(a):
	return ' '.join(list(map(str, a)))

def solve():
	(n, ki) = M()
	arr = L()
	arr.sort(reverse=True)
	print(sum(arr[:ki + 1]))
for _ in range(I()):
	solve()


ans = []
for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	ans.append(sum(a[:k + 1]))
for i in ans:
	print(i)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	for j in range(1, k + 1):
		if a[j - 1] != 0 and a[j] != 0:
			a[j] += a[j - 1]
			a[j - 1] = 0
	print(max(a) - min(a))


t = int(input())
for _ in range(t):
	(n, k) = (int(i) for i in input().split())
	a = sorted((int(i) for i in input().split()))
	res = sum(a[n - k - 1:n])
	print(res)


import io
import os
from collections import Counter, defaultdict, deque

def f(n, k, a):
	a.sort()
	diff = a[-1] - a[0]
	for b in range(k):
		bNum = n - 2 - b
		if a[bNum] == 0:
			return diff
		else:
			a[-1] += a[bNum]
			diff = a[-1]
	return diff
t = int(input())
result = []
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	result.append(f(n, k, a))
for i in range(t):
	print(result[i])


class Solution:

	def __init__(self):
		self.found = -1
		self.pattern = []
		self.three = 0
		self.five = 0
		self.seven = 0

	@staticmethod
	def maxPossibleDiff(barell, iters, water_present):
		if len(water_present) == 2:
			return sum(water_present)
		if sum(water_present) == 0:
			return 0
		if iters >= barell - 1:
			return sum(water_present)
		water_present = sorted(water_present)
		return water_present[-1] + sum(water_present[-iters - 1:-1])
num = int(input())
while num:
	(barell, iters) = input().split()
	water_liters = list(map(int, input().split()))
	val = Solution.maxPossibleDiff(int(barell), int(iters), water_liters)
	print(val)
	num -= 1


t = int(input())
for _ in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	lst = list(map(int, input().split()))
	lst = sorted(lst, reverse=True)
	ans = lst[0]
	i = 1
	for _ in range(k):
		ans += lst[i]
		i += 1
	print(ans)


import sys
input = sys.stdin.readline
T = int(input())
for t in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	total = sum(A)
	min_water = 0 if total > 0 else 0
	A.sort(reverse=True)
	max_water = A[0]
	for i in range(1, min(K + 1, N)):
		max_water += A[i]
	print(max_water - min_water)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if arr.count(0) == n:
		print(0)
	else:
		print(sum(arr[:k + 1]))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	l.sort()
	ind = n - 2
	for i in range(k):
		x = l[ind]
		l[-1] += x
		l[ind] = 0
		ind -= 1
	print(max(l) - min(l))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	print(sum(l[:k + 1]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	pos = n - 2
	for _ in range(k):
		A[n - 1] += A[pos]
		A[pos] = 0
		pos -= 1
	print(max(A) - min(A))


t = int(input())
for _ in range(0, t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort(reverse=True)
	for i in range(1, k + 1):
		a[0] += a[i]
	print(a[0])


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	for i in range(len(a) - 2, -1, -1):
		if k == 0:
			break
		if a[i] != 0:
			a[-1] += a[i]
			a[i] = 0
			k -= 1
	print(max(a) - min(a))


import heapq as hp

def find(arr, k):
	hp.heapify(arr)
	x = hp.heappop(arr)
	if x == 0:
		return 0
	else:
		while k > 0:
			x += hp.heappop(arr)
			k -= 1
		return -1 * x
for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = [-1 * i for i in arr]
	print(find(arr, k))


test = int(input())

def maximin(L, n, k):
	L.sort()
	m = 0
	for i in range(k + 1):
		m += L[-i - 1]
	return m
for loop in range(test):
	(n, k) = [int(x) for x in input().split()]
	L = [int(x) for x in input().split()]
	print(maximin(L, n, k))


I = lambda : map(int, input().split())
(t,) = I()
for _ in [0] * t:
	(n, k) = I()
	(*s,) = I()
	print(sum(sorted(s)[~k:]))


import heapq
for j in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	print(sum(l[~k:]))


def solution():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	s = 0
	for i in range(k + 1):
		s += l[i]
	print(s)
t = int(input())
for _ in range(t):
	solution()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(map(int, input().split()))
	print(sum(l[n - k - 1:]))


import math

def dtb(n):
	return bin(n).replace('0b', '')

def btd(n):
	return int(n, 2)
t = int(input())
for k in range(t):
	(n, kk) = map(int, input().split())
	a = list(map(int, input().split()))[:n]
	a.sort()
	su = a[n - 1]
	for i in range(n - 2, n - 2 - kk, -1):
		su += a[i]
	print(su)


n = int(input())
while n > 0:
	n -= 1
	(num, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	pos = -2
	for i in range(k):
		arr[-1] += arr[pos]
		pos -= 1
	print(arr[-1], end='\n')


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n - 1 <= k:
		print(sum(a))
	else:
		a.sort()
		i = n - 2
		cnt = 1
		sum1 = sum(a[n - 1 - k:n])
		print(sum1 - 0)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*arr,) = map(int, input().split())
	if k == 0:
		mn = min(arr)
		print(min((v - mn for v in arr)))
	else:
		k += 1
		arr.sort()
		print(sum(arr[-k:]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if sum(a) == 0:
		print(0)
	else:
		a.sort(reverse=True)
		a = a[1:] + [a[0]]
		i = 0
		while k > 0 and i < n - 1:
			if a[i] != 0:
				a[-1] += a[i]
				a[i] = 0
				k -= 1
				i += 1
			else:
				i += 1
		print(a[-1] - a[0])


def solve(n, k, arr):
	arr.sort()
	for i in range(n - 1, -1, -1):
		if k == 0:
			return arr[i]
		arr[i - 1] += arr[i]
		k -= 1
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(n, k, arr))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	for i in range(1, b + 1):
		l[0] += l[i]
		l[i] = 0
	print(l[0])


def solve():
	(n, k) = tuple(map(int, input().split()))
	barrels = list(map(int, input().split()))
	barrels.sort()
	sum = 0
	for i in range(k + 1):
		sum += barrels[n - 1 - i]
	print(sum)
t = int(input())
for i in range(t):
	solve()


from copy import copy
from math import inf
from collections import defaultdict, deque

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = sorted(map(int, input().split()))
		i = n - 2
		while k and i >= 0:
			a[n - 1] = a[n - 1] + a[i]
			a[i] = 0
			k -= 1
			i -= 1
		print(max(a) - min(a))
main()


t = int(input())
for tc in range(t):
	line = input().split()
	(n, k) = (int(line[0]), int(line[1]))
	line = input().split()
	arr = []
	for i in range(n):
		arr.append(int(line[i]))
	arr.sort()
	arr.reverse()
	for i in range(1, k + 1):
		arr[0] += arr[i]
		arr[i] = 0
	arr.sort()
	print(arr[-1] - arr[0])


def p(abn, k):
	ans = 0
	for i in range(0, k + 1):
		ans += abn[i]
	return ans
t = int(input())
res = list()
for i in range(0, t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	ab = [int(a) for a in input().split()]
	ab.sort()
	ab.reverse()
	tr = p(ab, k)
	res.append(tr)
for a in res:
	print(a)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())), reverse=True)
	print(sum(a[:k + 1]))


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	array.sort()
	temp = 2
	while k > 0:
		array[len(array) - 1] = array[len(array) - 1] + array[len(array) - temp]
		array[len(array) - temp] = 0
		k -= 1
		temp += 1
	print(array[len(array) - 1])
	t -= 1


import sys, math

def get_intl():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_int():
	return int(sys.stdin.readline().strip())

def get_strl():
	return sys.stdin.readline().strip().split()

def get_str():
	return sys.stdin.readline().strip()

def prt(msg=''):
	if isinstance(msg, list):
		sys.stdout.write(' '.join(map(str, msg)) + '\n')
	else:
		sys.stdout.write(str(msg) + '\n')
sys.setrecursionlimit(100000000)
MOD = 998244353

def solve():
	k = get_intl()
	barrels = get_intl()
	barrels.sort()
	prt(sum(barrels[k[1] * -1 - 1:]))

def main():
	haveTestCases = 1
	testCase = 1
	if haveTestCases:
		testCase = get_int()
	for i in range(testCase):
		solve()
main()


def main(arr, k):
	arr.sort()
	i = len(arr) - 2
	while k and i > -1 and arr[i]:
		arr[-1] += arr[i]
		arr[i] = 0
		k -= 1
		i -= 1
	x = min(arr)
	print(arr[-1] - x)
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split(' ')))
	arr = list(map(int, input().split(' ')))
	main(arr, b)


from itertools import permutations

def solve():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	for i in range(1, n):
		if k == 0:
			break
		l[0] += l[i]
		l[i] = 0
		k -= 1
	l.sort()
	print(l[-1] - l[0])
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	i = 0
	j = n - 2
	while i < k:
		a[n - 1] += a[j]
		a[j] = 0
		i += 1
		j -= 1
	print(a[n - 1])


n = int(input())
for h in range(n):
	k = int(input().split()[1])
	b = input().split()
	for h in range(len(b)):
		b[h] = int(b[h])
	b.sort()
	for h in range(k):
		try:
			b[-1] += b[-h - 2]
			b[-h - 2] = 0
		except:
			break
	print(b[-1])


t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	n = list(map(int, input().split()))
	n.sort(reverse=True)
	for i in range(1, len(n)):
		if k > 0:
			n[0] += n[i]
		k -= 1
	print(n[0])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	p = list()
	for i in range(k):
		p.append(l[i + 1])
	print(l[0] + sum(p))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, k) = LI()
		a = LI()
		a.sort(reverse=True)
		rr.append(sum(a[:k + 1]))
	return JA(rr, '\n')
print(main())


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	ans = 0
	ans = sum(arr[:k + 1])
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	l.sort(reverse=True)
	res = l[0]
	res += sum(l[1:k + 1])
	print(res)


n = int(input())
while n > 0:
	(n1, k) = map(int, input().split())
	d = list(map(int, input().split()))
	s = 0
	d = sorted(d)
	d = d[::-1]
	for i in range(0, k + 1):
		s += d[i]
	print(s)
	n -= 1


def solve():
	(barrels, pourings) = (int(x) for x in input().strip().split())
	water_amounts = [int(x) for x in input().strip().split()]
	water_amounts.sort()
	return sum(water_amounts[-pourings - 1:])
for _ in range(int(input().strip())):
	print(solve())


for _ in range(int(input())):
	(n, barr) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	ans = a[0]
	for i in range(1, barr + 1):
		ans += a[i]
	print(ans)


import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = sorted((int(x) for x in input().split()))
	print(sum(a[-(k + 1):]))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	print(sum(sorted(list(map(int, input().split())), reverse=True)[0:k + 1]))


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	(n, k) = tuple((int(x) for x in stdin.readline().split()))
	lst = sorted((int(x) for x in stdin.readline().split()))
	print(sum(lst[-k - 1:]))


from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(t,) = gil()
for _ in range(t):
	(n, k) = gil()
	a = gil()
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


def main():
	t = int(input())
	while t > 0:
		(n, k) = map(int, input().split())
		li = list(map(int, input().split()))
		li.sort()
		sumt = 0
		for i in range(n - 1, n - k - 2, -1):
			sumt = sumt + li[i]
		print(sumt)
		t -= 1
main()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	s = 0
	for i in range(min(k + 1, n)):
		s += a[i]
	print(s)


def main():
	for _ in range(int(input())):
		(n, k) = list(map(int, input().split()))
		a = list(map(int, input().split()))
		a.sort()
		for i in range(k):
			a[-1] += a[-1 - i - 1]
			a[-2 - i] = 0
		print(a[-1])
main()


def readis():
	return map(int, input().strip().split())
T = int(input())
while T:
	T -= 1
	(n, k) = readis()
	xs = sorted(readis(), reverse=True)
	if k == 0:
		print(xs[0] - xs[-1])
	else:
		print(sum(xs[:k + 1]))


import heapq

def compute(barrels, k):
	if len(barrels) == 1:
		return barrels
	heapq.heapify(barrels)
	for i in range(k):
		curMax = heapq.heappop(barrels)
		nextMax = heapq.heappop(barrels)
		heapq.heappush(barrels, -(-curMax - nextMax))
		heapq.heappush(barrels, 0)
	return -heapq.heappop(barrels)
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split() if x]
	barrels = [-int(x) for x in input().split() if x]
	print(compute(barrels, k))


count = int(input())
for i in range(count):
	li1 = list(map(int, input().split()))
	(x, s) = (li1[0], li1[1])
	li = list(map(int, input().split()))
	li.sort()
	sum = li[x - 1]
	ind = x - 2
	while s > 0 and ind > -1:
		sum += li[ind]
		ind -= 1
		s -= 1
	else:
		li[x - 1] = 0
	li.sort()
	print(sum)


tc = int(input())
for _ in range(tc):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())), reverse=True)
	j = 1
	for i in range(k):
		l[0] += l[j]
		l[j] = 0
		j += 1
	print(max(l) - min(l))


t = int(input())
while t:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	arr.sort()
	print(sum(arr[n - 1 - k:]))


test = int(input())
for t in range(test):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	ans = l[0]
	for i in range(1, k + 1):
		ans += l[i]
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	p = -(1 + k * 1)
	mox = sum(arr[p:])
	print(mox)


def process():
	(n, k) = list(map(int, input().split()))
	li = list(map(int, input().split()))
	li.sort()
	start = n - 2
	end = n - 1
	i = 1
	while k > 0 and start >= 0:
		if li[start] == 0:
			start -= 1
		else:
			li[end] += li[start]
			li[start] = 0
			k -= 1
			start -= 1
	li.sort()
	print(li[-1] - li[0])
tests = int(input())
for i in range(tests):
	process()


t = int(input())
for _ in range(t):
	(n, k) = tuple(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	a.sort(reverse=True)
	ans = sum(a[:k + 1])
	print(ans)


rn = lambda : int(input())
rns = lambda : map(int, input().split())
rl = lambda : list(map(int, input().split()))
rs = lambda : input()
yn = lambda x: print('Yes') if x else print('No')
YN = lambda x: print('YES') if x else print('NO')
pl = lambda l: print(' '.join(list(map(str, l))))
for _ in range(rn()):
	(n, k) = rns()
	l = rl()
	l.sort()
	ans = l[-1] - l[0]
	a = True
	for i in range(k):
		if a:
			a = False
			ans += l[0]
		ans += l[-2 - i]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	n = len(arr)

	def solve():
		if n == 1:
			return 0
		else:
			ans = 0
			for i in range(min(k + 1, n)):
				ans += arr[i]
			return ans
	result = solve()
	print(result)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = len(a) - 2
	for i in range(k):
		a[-1] += a[c]
		a[c] = 0
		c -= 1
	print(max(a) - min(a))


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


from bisect import *
from collections import *
from math import *
from heapq import *
from typing import List
from itertools import *
from operator import *
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

@lru_cache(None)
def fact(x):
	if x < 2:
		return 1
	return fact(x - 1) * x

@lru_cache(None)
def per(i, j):
	return fact(i) // fact(i - j)

@lru_cache(None)
def com(i, j):
	return per(i, j) // fact(j)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 1
	res = 0
	for w in arr:
		res += w
		if res > x:
			res = w
		c += 1
	return c

def lowbit(n):
	return n & -n

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d
t = N()
for i in range(t):
	(n, k) = RL()
	arr = RLL()
	arr.sort(reverse=True)
	if n == 1:
		ans = 0
	else:
		for i in range(min(k, n - 1)):
			arr[i + 1] += arr[i]
			arr[i] = 0
		ans = arr[i + 1]
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	if k >= n - 1:
		print(sum(s))
		continue
	s.sort()
	s.reverse()
	print(sum(s[:k + 1]))


from sys import stdout, stdin
from io import IOBase, BytesIO
from os import read, write, fstat
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size: int=...):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')

def barrel_pouring(total_barrels, num_pourings, barrels_list):
	if num_pourings == 0:
		print(str(max(barrels_list) - min(barrels_list)))
		return
	if num_pourings >= total_barrels - 1:
		print(str(sum(barrels_list)))
		return
	barrels_list.sort()
	top_barrels = barrels_list[-(num_pourings + 1):]
	print(str(sum(top_barrels)))
test_cases = int(input())
for _ in range(test_cases):
	(barrels, pours) = map(int, input().split(' '))
	barrels_rep = [int(i) for i in input().split(' ')]
	barrel_pouring(barrels, pours, barrels_rep)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()
for _ in range(II()):
	(n, k) = MI()
	aa = LI()
	aa.sort(reverse=True)
	print(sum(aa[:k + 1]))


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	if l[0] == 0:
		print(0)
	else:
		s = 0
		for i in range(b + 1):
			s += l[i]
		print(s)


import sys
import math
import collections

def scan(input_type='int'):
	return list(map(int, sys.stdin.readline().strip().split()))

def solution():
	for _ in range(int(input())):
		(n, k) = scan()
		a = scan()
		a.sort()
		a.reverse()
		if len(set(a)) == 1 and a[0] == 0:
			print(0)
		elif len(a) == 1:
			print(a[0])
		else:
			s = 0
			for i in range(k + 1):
				s += a[i]
			print(s)
solution()


import sys
import math
from collections import Counter, defaultdict
LI = lambda : list(map(int, input().split()))
MAP = lambda : map(int, input().split())
IN = lambda : int(input())
S = lambda : input()

def case():
	(n, k) = MAP()
	a = LI()
	a.sort(reverse=True)
	print(sum(a[:k + 1]))
for _ in range(IN()):
	case()


import heapq
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	K = k
	while k > 0 and len(a) > 1:
		one = a.pop()
		two = a.pop()
		a.append(one + two)
		k -= 1
		flag = True
	if flag:
		print(a[-1])
		continue
	print(a[-1] - a[0])


try:
	x = int(input())
	for _ in range(x):
		a = list(map(int, input().split()))
		b = list(map(int, input().split()))
		z = a[1]
		b.sort()
		for c in range(z):
			b[-1] = b[-1] + b[-c - 2]
			b[-c - 2] = 0
		print(b[-1])
except:
	pass


t = int(input())
for l in range(0, t):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	s.sort()
	print(sum(s[max(0, n - k - 1):]))


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]

def solve():
	(n, k) = idata()
	data = sorted(idata())
	ans = data[-1]
	for i in range(n - 2, n - 2 - k, -1):
		ans += data[i]
	print(ans)
	return
for t in range(int(ii())):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	a.sort(reverse=True)
	print(sum(a[0:k + 1]))


T = int(input())
ans_ls = [0] * T
for t in range(T):
	(N, K) = map(int, input().split())
	a_ls = list(map(int, input().split()))
	a_ls.sort(reverse=True)
	print(sum(a_ls[:K + 1]))


n = int(input())
for _ in range(n):
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	print(sum(sorted(a)[::-1][:min(n, k + 1)]))


import heapq
import collections
from math import log2
import itertools
from functools import lru_cache
from sys import setrecursionlimit as srl
srl(2 * 10 ** 6)
N = 200001

def solve(a, k):
	a.sort(reverse=True)
	return sum(a[:k + 1])
t = int(input())
for tc in range(1, t + 1):
	(n, k) = map(int, input().split())
	in_ = map(int, input().split())
	a = []
	for x in in_:
		a.append(x)
	print(solve(a, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ls = [int(a) for a in input().split()]
	ls.sort(reverse=True)
	print(sum(ls[:min(k + 1, n)]))


import os
from io import BytesIO, IOBase
import sys
from collections import defaultdict, deque, Counter
from bisect import *
from math import sqrt, pi
import math
from itertools import permutations
from copy import deepcopy

def main():
	for t in range(int(input())):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		a.sort(reverse=True)
		su = a[0]
		for i in range(1, n):
			su += a[i]
			k -= 1
			if k == 0:
				break
		print(su)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import math
from operator import itemgetter, attrgetter, methodcaller
input = sys.stdin.readline
ttt = int(input())
for tt in range(ttt):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if sum(a) == 0:
		print(0)
		continue
	a.sort(reverse=True)
	s = 0
	for i in range(min(n, k + 1)):
		s += a[i]
	print(s)


import math
test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if n == 1:
		print(0)
	elif k == 0:
		print(max(arr) - min(arr))
	else:
		arr.sort()
		m = n - 1
		for i in range(k):
			arr[m] += arr[m - 1]
			arr.pop(m - 1)
			m -= 1
		print(max(arr))


def ans(a, k):
	if k >= len(a):
		return sum(a)
	else:
		a.sort(reverse=True)
		return sum(a[:k + 1])
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	print(ans(a, k))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	barrels = list(map(int, input().split()))
	barrels.sort(reverse=True)
	print(sum(barrels[:k + 1]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a_i = list(map(int, input().split()))
	a_i = sorted(a_i)
	print(sum(a_i[-k - 1:]))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a = a[::-1]
	mx = sum(a[:k + 1])
	print(mx)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if max(a) == 0:
		print(0)
	else:
		a.sort()
		p = 0
		if k == 1:
			print(a[-1] + a[-2])
		else:
			for i in range(-k - 1, -1):
				p += a[i]
			print(a[-1] + p)


l = []
t = int(input())
for _ in range(t):
	(a, b) = map(int, input().split())
	l1 = list(map(int, input().split()))
	l1 = sorted(l1)
	l2 = l1[-b - 1:]
	l.append(sum(l2))
for i in l:
	print(i)


def solve(n, k):
	s = list(map(int, input().split()))
	if k == 0:
		print(max(s) - min(s))
		return
	s.sort()
	s.reverse()
	ans = 0
	for i in range(k + 1):
		ans += s[i]
	print(ans)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	solve(n, k)


def solve():
	s = [int(i) for i in input().split()]
	n = s[0]
	k = s[1]
	s = [int(i) for i in input().split()]
	s.sort()
	for i in range(1, k + 1):
		s[n - 1] += s[n - 1 - i]
	print(s[n - 1])
t = int(input())
for i in range(t):
	solve()


import sys
import heapq
import copy
import math
import decimal
input = sys.stdin.readline

def binary_exponentiation(a, b):
	ans = 1
	while b != 0:
		bit = b % 2
		if bit == 1:
			ans = ans * a
		a = a * a
		b = b // 2
	return ans

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def insr2():
	s = input()
	s = list(s[:len(s) - 1])
	s = [ord(s[i]) - ord('a') for i in range(len(s))]
	return s

def invr():
	return map(int, input().split())
ans = 0

def pr_list(a):
	print(*a, sep=' ')

def swap(a, b):
	temp = a
	a = b
	b = temp
	return [a, b]

def pri(a, b):
	s = '? ' + str(a) + ' ' + str(b)
	print(s)
	sys.stdout.flush()
result = []

def nCk(arr, itr, k, n):
	if len(arr) == k:
		result.append(arr)
		return
	if len(arr) > k or itr == n + 1:
		return
	nCk(arr + [itr], itr + 1, k, n)
	nCk(arr, itr + 1, k, n)
	return

def nPk(arr, itr, k, n):
	if len(arr) == k:
		result.append(arr)
		return
	if len(arr) > k or itr == n + 1:
		return
	for i in range(len(arr) + 1):
		nPk(arr[0:i] + [itr] + arr[i:len(arr)], itr + 1, k, n)
	nPk(arr, itr + 1, k, n)
	return

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	ans = 0
	stack = []
	arr = []
	heapq.heapify(arr)
	for test in range(tests):
		(n, k) = inlt()
		a = inlt()
		a.sort()
		for i in range(k):
			a[-1] = a[-1] + a[n - i - 2]
			a[n - i - 2] = 0
		a.sort()
		print(a[-1] - a[0])
main()


a = int(input())
for i in range(0, a):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	d.sort()
	e = d[::-1]
	j = max(d)
	for i in range(1, c + 1):
		j += e[i]
	print(j)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	if l[-1] == 0 and l[0] == 0:
		print('0')
	else:
		for i in range(n):
			if k > 0:
				if l[i + 1] > 0:
					l[0] += l[i + 1]
				k -= 1
		print(l[0])


def main():
	(n, k) = map(int, input().split())
	arr = list(sorted(list(map(int, input().split())), reverse=True))
	m = arr[0]
	for i in range(1, k + 1):
		m += arr[i]
	print(m)
for _ in range(int(input())):
	main()


import sys
input = sys.stdin.readline
inputLines = sys.stdin.readlines

def readIntList():
	return list(map(int, input().split()))

def readStrList():
	return list(map(lambda x: x.strip(), inputLines()))

def indexOf(l: list, elem: int):
	return l.index(elem) if elem in l else -1

def lastIndexOf(l: list, elem: int):
	indexes = [idx for (idx, val) in enumerate(l) if val == elem]
	return max(indexes) if len(indexes) > 0 else -1

def solution():
	for _ in range(int(input())):
		data = readIntList()
		(n, k) = (data[0], data[1])
		l = readIntList()
		l.sort(reverse=True)
		for i in range(1, k + 1):
			if i < n and l[i] > 0:
				l[0] += l[i]
			else:
				break
		print(l[0])
solution()


import sys
import heapq
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		(N, K) = [int(x) for x in input().split()]
		A = [int(x) for x in input().split()]
		A.sort(reverse=True)
		ans = 0
		for i in range(min(N, K + 1)):
			ans += A[i]
		print(ans)
main()


def solve(n, k, l):
	l.sort()
	return sum(l[-k - 1:])
for i in range(int(input())):
	print(solve(*map(int, input().split()), list(map(int, input().split()))))


from sys import stdin
import math
t = int(stdin.readline().strip())
for _ in range(t):
	(n, k) = [int(x) for x in stdin.readline().strip().split(' ')]
	arr = [int(x) for x in stdin.readline().strip().split(' ')]
	arr.sort(key=lambda x: -x)
	print(arr[0] + sum(arr[1:1 + k]))


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	for i in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		sa = sorted(a)
		print(sum(sa[n - k - 1:]))
main()


ans = []
t = int(input())
for i in range(t):
	(n, k) = input().split()
	k = int(k)
	n = int(n)
	data = list(map(int, input().split()))
	data = sorted(data)
	if k > 0 and data[n - 1] > 0 and (k < n):
		p = 1
		while p <= k:
			p += 1
			data[n - 1] += data[n - p]
	ans.append(data[n - 1])
for r in ans:
	print(r)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	if n == 1:
		print(a[0])
	else:
		ans = a[0]
		for i in range(1, k + 1):
			ans += a[i]
		print(ans)


t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	c = 0
	i = n - 2
	while i >= 0:
		if k > 0:
			temp = a[i]
			a[i] = 0
			a[n - 1] += temp
			k -= 1
		i -= 1
	print(a[n - 1])


for i in range(int(input())):
	m = list(map(int, input().split()))
	n = list(map(int, input().split()))
	n.sort(reverse=True)
	a = 0
	for j in range(m[1] + 1):
		a = a + n[j]
	print(a)


import sys
input = sys.stdin.readline
(inp, ip) = (lambda : int(input()), lambda : [int(w) for w in input().split()])
for _ in range(inp()):
	(n, k) = ip()
	x = ip()
	x.sort(reverse=True)
	print(sum(x[:k + 1]))


from sys import stdin, stdout
import math
import heapq
import collections
input = stdin.readline

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]

def inputstrings():
	return [x for x in input().split()]

def inputstringnum():
	return [ord(x) - ord('a') for x in input()]

def inputmatrixchar(rows):
	arr2d = [[j for j in input().strip()] for i in range(rows)]
	return arr2d

def inputmatrixint(rows):
	arr2d = []
	for _ in range(rows):
		arr2d.append([int(i) for i in input().split()])
	return arr2d
t = int(input())
for q in range(t):
	(n, k) = inputnums()
	a = inputlist()
	a.sort(reverse=True)
	sm = 0
	for i in range(min(n, k + 1)):
		sm += a[i]
	print(sm)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	max_ = l[0]
	j = 1
	for i in range(b):
		max_ += l[j]
		l[j] = 0
		j += 1
	print(max_ - min(l[1:]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	s = sum(l[-m - 1:])
	print(s)


t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	list1 = list(map(int, input().split()))
	list1.sort()
	print(sum(list1[n - k - 1:]))
	t -= 1


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	i = n - 2
	if k >= n:
		ans = sum(a)
	else:
		ans = a[-1]
		while i >= 0 and k:
			ans += a[i]
			a[i] = 0
			i -= 1
			k -= 1
	print(ans)


def barrel(n, k, a):
	if k == 0:
		return max(a) - min(a)
	a.sort(reverse=True)
	return sum(a[:k + 1])
n = int(input())
res = []
for i in range(n):
	num1 = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	res.append(barrel(num1[0], num1[1], arr))
for j in res:
	print(j)


import sys
input = sys.stdin.readline

def solve():
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	L.sort()
	if min(L) == max(L) == 0:
		print(0)
		return
	print(sum(L[-1:-2 - k:-1]) - 0)
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	V = list(map(int, input().split()))
	V.sort()
	print(sum(V[-K - 1:]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	v = sum(A[n - k - 1:])
	print(v)


from sys import stdin
nii = lambda : map(int, stdin.readline().split())
lnii = lambda : list(map(int, stdin.readline().split()))
t = int(input())
for tt in range(t):
	(n, k) = nii()
	a = lnii()
	a.sort()
	max_a = a[-1]
	l = []
	for i in range(n - 2, -1, -1):
		l.append(a[i])
	l.sort(reverse=True)
	ans = max_a + sum(l[:k])
	print(ans)


test = int(input())
for _ in range(test):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	maxv = sum(arr[:k + 1])
	print(maxv)


def solve():
	(n, k) = map(int, input().split())
	if n == 1:
		print(0)
		return
	ls = list(map(int, input().split()))
	ls.sort()
	res = ls.pop()
	for i in range(k):
		if ls:
			res += ls.pop()
	print(res)
	return
for _ in range(int(input())):
	solve()


for _ in range(int(input())):
	a1 = [int(_) for _ in input().split()]
	a2 = sorted([int(_) for _ in input().split()], reverse=True)
	a2.append(0)
	f = a2[-1]
	for i in range(a1[1] + 1):
		f += a2[i]
	print(f)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	s = 0
	for j in range(k + 1):
		s += a[j]
	print(s)


t = int(input())
for _ in range(t):
	(n, k) = [int(i) for i in input().split()]
	A = [int(i) for i in input().split()]
	A.sort(reverse=True)
	ans = sum(A[:k + 1])
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	s = l[-1]
	x = n - 2
	while k > 0 and x >= 0:
		s += l[x]
		x -= 1
		k -= 1
	print(s)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	lst = list(map(int, input().split()))
	s = 0
	lst.sort(reverse=True)
	for i in range(1, m + 1):
		if m >= n:
			break
		s += lst[i]
	print(s + lst[0])


def barrel(values, k):
	values.sort(reverse=True)
	a = sum(values[0:k + 1])
	return a
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	values = list(map(int, input().split()))
	print(barrel(values, k))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	if sum(l) == 0:
		print(0)
	else:
		f = 0
		for i in range(k):
			f += l[n - i - 2]
		print(f + l[n - 1])


for i in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	vols = sorted([int(x) for x in input().split()], reverse=True)
	print(sum(vols[:k + 1]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	for i in range(k):
		if -i - 2 < -len(a):
			break
		a[-1] += a[-i - 2]
	print(a[-1])


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if k > n - 1:
		k = n - 1
	for i in range(k):
		arr[0] += arr[i + 1]
		arr[i + 1] = 0
	print(max(arr) - min(arr))


import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
letters = ascii_letters[:26]
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = sorted(list(map(int, input().split())), reverse=True)
	if k == 0:
		print(arr[0] - arr[-1])
		continue
	res = arr[0]
	ind = 1
	while k > 0 and ind < n:
		res += arr[ind]
		k -= 1
		ind += 1
	print(res)


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	print(sum(l[-k - 1:]))


t = int(input())
while t:
	t -= 1
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	print(sum(arr[-k:]) + arr[n - k - 1])


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if arr[-1] == 0:
		print(0)
	else:
		ans = arr[-1]
		for i in range(n - 2, -1, -1):
			if k:
				ans += arr[i]
				k -= 1
			else:
				break
		print(ans)


t = int(input())
for _ in range(t):
	l = list(map(int, input().split()))
	(n, k) = (l[0], l[1])
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	val = min(k, n - 1)
	for i in range(1, k + 1):
		a[0] += a[i]
		a[i] = 0
	print(a[0])


t = int(input())
max_diff = 0
for i in range(t):
	info = list(map(int, input().split()))
	array = list(map(int, input().split()))
	array.sort()
	n = len(array)
	for k in range(n - info[1] - 1, n - 1):
		array[n - 1] += array[k]
		array[k] = 0
	max_diff = array[n - 1]
	print(max_diff)


t = int(input())
for i in range(0, t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	ans = a[n - 1]
	l = n - 2
	while k > 0:
		if l < 0:
			break
		ans = ans + a[l]
		l = l - 1
		k = k - 1
	print(ans)


import sys
infile = sys.stdin
next(infile)
for line in infile:
	l1 = list(map(int, line.split()))
	n = l1[0]
	k = l1[1]
	l2 = list(map(int, infile.readline().split()))
	l2.sort()
	if l2[-1] == 0:
		print(0)
	else:
		ans = 0
		n = min(len(l2), k + 1)
		for i in range(n):
			ans += l2[len(l2) - 1 - i]
		print(ans)


t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	max_a = a[0]
	p = 1
	for j in range(k):
		if k + 1 <= n and p <= n - 1:
			max_a += a[p]
			p += 1
	print(max_a)


for _ in range(int(input())):
	(n, k) = [int(_) for _ in input().split()]
	A = sorted([int(_) for _ in input().split()], reverse=True)
	ans = 0
	for _ in range(1, k + 1):
		ans += A[_]
	print(ans + A[0])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	print(sum(A[n - k - 1:]))


for _ in range(int(input())):
	(N, k) = [int(x) for x in input().split()]
	barrels = sorted([int(x) for x in input().split()])
	if k >= N:
		k = N - 2
	print(sum(barrels[N - k - 1:]))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	ma = sum(arr[:k + 1])
	print(ma)


for _ in ' ' * int(input()):
	(a, b) = map(int, input().split())
	z = sorted(map(int, input().split()), reverse=True)
	print(sum(z[:b + 1]))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l = l[::-1]
	s = l[0]
	for i in range(k):
		s += l[i + 1]
	print(s)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a, reverse=True)
	add = 0
	x = 0
	for x in range(k + 1):
		add = add + a[x]
	print(add)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(i) for i in input().split()]
	arr.sort(reverse=True)
	print(sum(arr[:k + 1]))


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	i = n - 2
	while i >= 0 and k > 0:
		a[-1] += a[i]
		a[i] = 0
		k -= 1
		i -= 1
	print(a[-1] - min(a))

def main():
	t = 1
	t = int(input())
	for _ in range(t):
		solve()
main()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = [int(i) for i in input().split()]
	s.sort()
	if s[n - 1] == 0:
		print(0)
	else:
		for j in range(n - 2, n - 2 - k, -1):
			s[n - 1] += s[j]
		print(s[n - 1])


t = int(input())
while t:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	if n == 1:
		print(0)
	else:
		s = 0
		l1 = l[:n - 1]
		l2 = l1[::-1]
		for i in range(k):
			s += l2[i]
		print(l[-1] + s)
	t = t - 1


def main():
	import sys
	sys.setrecursionlimit(311111)
	ikimasu = sys.stdin.buffer.readline
	ini = lambda : int(ins())
	ina = lambda : list(map(int, ikimasu().split()))
	ins = lambda : ikimasu().strip()
	t = ini()
	for _ in range(t):
		(n, k) = ina()
		tmp = ina()
		tmp.sort()
		tmp.reverse()
		index = 1
		rick = 0
		k += 1
		for i in tmp:
			if k == 0:
				break
			rick += i
			k -= 1
		print(rick)
main()


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range
R = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def MI():
	return map(int, input().split())

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def NLI(n):
	return [[int(i) for i in input().split()] for i in range(n)]

def NLI_(n):
	return [[int(i) - 1 for i in input().split()] for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def RLI(n=8, a=1, b=10):
	return [random.randint(a, b) for i in range(n)]

def RI(a=1, b=10):
	return random.randint(a, b)

def INP():
	N = 10
	A = 10
	n = random.randint(1, N)
	a = [random.randint(1, A) for i in range(n)]
	return (n, a)

def Rtest(T):
	(case, err) = (0, 0)
	for i in range(T):
		inp = INP()
		a1 = naive(*inp)
		a2 = solve(*inp)
		if a1 != a2:
			print((a1, a2), inp)
			err += 1
		case += 1
	print('Tested', case, 'case with', err, 'errors')

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in R(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in R(base ** n):
		s = [tb // base ** bt % base for bt in R(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def YN(x):
	print(['NO', 'YES'][x])

def Yn(x):
	print(['No', 'Yes'][x])

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class UnionFind:

	def __init__(self, n):
		self.table = [-1] * n

	def _root(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self._root(self.table[x])
			return self.table[x]

	def find(self, x, y):
		return self._root(x) == self._root(y)

	def union(self, x, y):
		r1 = self._root(x)
		r2 = self._root(y)
		if r1 == r2:
			return
		d1 = self.table[r1]
		d2 = self.table[r2]
		if d1 <= d2:
			self.table[r2] = r1
			if d1 == d2:
				self.table[r1] -= 1
		else:
			self.table[r1] = r2

	def __str__(self):
		rt = [i if j < 0 else j for (i, j) in enumerate(self.table)]
		return str(rt)
show_flg = False
show_flg = True
ans = 0
for _ in range(I()):
	(n, k) = LI()
	a = LI()
	print(sum(sorted(a)[-k - 1:]))


from sys import stdin, stdout

class SOLVE:

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(n, k) = [int(x) for x in R().split()]
			a = [int(x) for x in R().split()]
			a.sort(reverse=True)
			for j in range(1, min(k + 1, n)):
				a[0] += a[j]
			ans.append(str(a[0]))
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


n = int(input())
for i in range(n):
	(n, k) = map(int, input().split())
	bars = sorted(list(map(int, input().split())))
	print(sum(bars[-k - 1:]))


t = int(input())
for _ in range(t):
	(n, k) = (int(x) for x in input().split())
	a = [int(x) for x in input().split()]
	a.sort(reverse=True)
	s = a[:k + 1]
	print(sum(s))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	maxim = arr[0]
	for i in range(1, n):
		maxim += arr[i]
		k -= 1
		arr[i] = 0
		if k == 0:
			break
	print(maxim - min(arr))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math
import bisect
from collections import Counter
import bisect
from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = sorted(list(map(int, input().split())))
	val = 0
	ma = arr[-1]
	mi = -1
	for i in range(n - 2, -1, -1):
		val += 1
		if val > k:
			break
		arr[-1] += arr[i]
		arr[i] = 0
	print(arr[-1] - min(arr))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	cum = [a[0]]
	for i in range(n - 1):
		cum.append(cum[i] + a[i + 1])
	cum.append(cum[-1])
	print(cum[k])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = [int(i) for i in input().split()]
	lst.sort(reverse=True)
	res = 0
	for i in range(k + 1):
		res += lst[i]
	print(res)


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	(N, K) = getInts()
	A = getInts()
	A.sort(reverse=True)
	return sum(A[:K + 1])
for _ in range(getInt()):
	print(solve())


from sys import stdin, stdout
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	arr = list(map(int, stdin.readline().split()))
	arr.sort()
	i = len(arr) - 2
	while k != 0 and i >= 0:
		arr[n - 1] += arr[i]
		i -= 1
		k -= 1
	print(arr[n - 1])


t = int(input())
for f in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	a = sum(l[n - k - 1:])
	print(a)


for _ in range(int(input())):
	(total, pourings) = map(int, input().split())
	barrel = list(map(int, input().split()))
	barrel.sort()
	difference = barrel[total - 1] - barrel[total - 2]
	x = 2 * barrel[total - 2]
	barrel.pop(total - 1)
	barrel.pop(total - 2)
	barrel.append(x)
	for _ in range(pourings):
		difference += barrel.pop()
	print(difference)


def read_int() -> int:
	return int(input())

def read_ints():
	return map(int, input().split(' '))

def test_case():
	((_, k), a) = (tuple(read_ints()), read_ints())
	print(sum((elem for (_, elem) in zip(range(k + 1), sorted(a, reverse=True)))))
for _ in range(read_int()):
	test_case()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = sorted(list(map(int, input().split())))
	print(sum(li[-k - 1:]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	s = 0
	for i in range(n - 2, n - k - 2, -1):
		s += a[i]
		a[i] = 0
	print(a[n - 1] + s)


for OvO in range(int(input())):
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	L.sort()
	L = L[::-1]
	print(sum(L[:k + 1]))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	max_stored = A[-1]
	i = n - 2
	while i >= 0 and k > 0:
		max_stored += A[i]
		i -= 1
		k -= 1
	print(max_stored)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	arr.sort(reverse=True)
	ma = arr[0]
	mi = arr[-1]
	i = 1
	while k > 0 and i < n:
		ma += arr[i]
		i += 1
		k -= 1
	if i > 1:
		print(ma)
	else:
		print(ma - mi)


t = int(input())
for j in range(t):
	(n, m) = map(int, input().strip().split())
	l = list(map(int, input().strip().split()))
	res = 0
	l.sort(reverse=True)
	for i in range(m + 1):
		res += l[i]
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	if sum(arr) == 0:
		print(0)
		continue
	newarr = sorted(arr, reverse=True)
	for j in range(1, k + 1):
		newarr[0] += newarr[j]
		newarr[j] = 0
	print(newarr[0] - sorted(newarr)[0])


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	count = arr[0]
	for km in range(min(k, len(arr) - 1)):
		count += arr[km + 1]
	print(count)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	array = sorted(array, reverse=True)
	suma = sum(array[0:k + 1])
	print(suma)


t = int(input())
for i in range(t):
	a = input()
	b = input()
	n = int(a.split()[0])
	k = int(a.split()[1])
	c = b.split()
	for j in range(len(c)):
		c[j] = int(c[j])
	c.sort(reverse=True)
	sum = 0
	for i in range(k + 1):
		sum += c[i]
	print(sum)


def solve(barrels, transfusion_count):
	if len(barrels) <= 1:
		return 0
	barrels.sort(reverse=True)
	b_0 = barrels[0]
	if transfusion_count == 0:
		return b_0 - barrels[-1]
	for i in range(1, min(transfusion_count + 1, len(barrels))):
		b = barrels[i]
		if b == 0:
			return b_0
		b_0 += b
	return b_0
t = int(input())
for _ in range(t):
	(_, transfusion_count) = (int(i) for i in input().split(' '))
	barrels = [int(i) for i in input().split(' ')]
	a = solve(barrels, transfusion_count)
	print(a)


t = int(input())
for _ in range(t):
	int_list = [int(i) for i in input().split()]
	barrels = [int(i) for i in input().split()]
	n = int_list[0]
	k = int_list[1]
	barrels.sort(reverse=True)
	if n > 0:
		res = barrels[0]
		for i in range(1, min(n, k + 1)):
			res += barrels[i]
	else:
		res = 0
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	max = arr[-1]
	for i in range(1, k + 1):
		max += arr[-i - 1]
	print(max - 0)


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	inp = list(map(int, input().split()))
	inp.sort()
	s = 0
	for i in range(n - k - 1, n):
		s += inp[i]
	print(s)


def main():
	(n, k) = map(int, input().split())
	v = sorted(list(map(int, input().split())))
	v1 = v[0]
	v2 = 0
	for i in range(n - k - 1, n):
		v2 += v[i]
	print(v2 - 0)
t = int(input())
for i in range(t):
	main()


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
sys.setrecursionlimit(10 ** 6)
I = sys.stdin.readline

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def valid(row, col, rows, cols, rcross, lcross):
	return rows[row] == 0 and cols[col] == 0 and (rcross[col + row] == 0) and (lcross[col - row] == 0)

def main():
	ans = ''
	for _ in range(ii()):
		(n, k) = mi()
		arr = sorted(li())
		for i in range(k):
			arr[n - 1] += arr[n - 2 - i]
		ans += str(arr[n - 1]) + '\n'
	print(ans)
main()


from sys import stdin, stdout
for q in range(int(input())):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	if set(array) == {0}:
		print(0)
	else:
		array.sort()
		j = n - 2
		while k and j >= 0:
			if array[j] != 0:
				array[n - 1] += array[j]
				array[j] = 0
				j -= 1
				k -= 1
			else:
				j -= 1
		print(max(array) - min(array))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	p = sum(a[n - k - 1:n - 1])
	d = a[-1] + p
	print(d)


def solve(N, K, arr):
	arr.sort(reverse=True)
	ans = 0
	for i in range(1, min(K + 1, N)):
		ans += arr[i]
	return arr[0] + ans
T = int(input())
for t in range(T):
	(N, K) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	ans = solve(N, K, arr)
	print(ans)


for _ in range(int(input())):
	(a, b) = list(map(int, input().split()))
	l = list(map(int, input().split()))
	if l.count(0) == a:
		print(0)
	else:
		l.sort(reverse=True)
		d = l[0]
		if b == 0:
			print(l[0] - l[a - 1])
		for i in range(1, a):
			if b == 0:
				break
			if l[i] > 0:
				d += l[i]
				b -= 1
		print(d)


try:
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		litres = list(map(int, input().split()))
		litres.sort(reverse=True)
		(maximum, minimum) = (0, 0)
		for i in range(k + 1):
			maximum += litres[i]
			if i != 0:
				litres[i] = 0
		minimum = min(litres)
		ans = maximum - minimum
		print(ans)
except:
	pass


import sys
t = int(input())

def answer(n, k, a):
	a.sort()
	if n > k:
		print(sum(a[n - k - 1:]))
	else:
		print(sum(a))
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	answer(n, k, a)


from bisect import *
from math import *
from collections import Counter, defaultdict
I = lambda : int(input())
M = lambda : map(int, input().split())
LI = lambda : list(map(int, input().split()))

def solve():
	(n, k) = M()
	a = LI()
	a.sort()
	a.reverse()
	print(sum(a[0:k + 1]))
for _ in range(I()):
	solve()


case = int(input())
for i in range(case):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = 0
	for j in range(k + 1):
		ans += a[-1 - j]
	print(ans)


t = int(input())
for _ in range(t):
	answer = 0
	(n, k) = map(int, input().split())
	barrels = list(map(int, input().split()))
	barrels.sort()
	max_water = barrels[-1]
	for i in range(1, k + 1):
		max_water += barrels[-1 - i]
	answer = max_water
	print(answer)


t = int(input())
for i in range(t):
	(n, p) = list(map(int, input().split()))
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	print(sum(w[0:p + 1]))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	for i in range(n - 2, max(-1, n - k - 2), -1):
		l[-1] += l[i]
	print(l[-1])
	t -= 1


import heapq

def find(arr, k):
	heap = []
	for i in range(len(arr)):
		heapq.heappush(heap, -1 * arr[i])
	total = heapq.heappop(heap)
	for i in range(k):
		val = heapq.heappop(heap)
		total += val
	return -1 * total
T = int(input())
for t in range(T):
	(n, k) = [int(i) for i in input().split(' ')]
	arr = [int(i) for i in input().split(' ')]
	print(find(arr, k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	barrels = sorted(l)[::-1]
	s = barrels[0]
	m = min(barrels)
	for i in range(1, min(n, k + 1)):
		if barrels[i] == 0:
			i = k
		else:
			s += barrels[i]
			barrels[i] = 0
			m = 0
	if k > 0:
		m = 0
	print(s - m)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	A = sorted(list(map(int, input().split())))
	A.reverse()
	ans = 0
	print(sum(A[:min(n, k + 1)]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().strip(' ').split(' '))
	arr = list(map(int, input().strip(' ').split(' ')))
	arr.sort()
	x = arr.pop()
	for i in range(min(n - 1, k)):
		x += arr.pop()
	print(x)


from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
	from io import BytesIO as stream
else:
	from io import StringIO as stream
if sys.version_info[0] < 3:

	class dict(dict):

		def items(self):
			return dict.iteritems(self)

		def keys(self):
			return dict.iterkeys(self)

		def values(self):
			return dict.itervalues(self)
	input = raw_input
	range = xrange
	filter = itertools.ifilter
	map = itertools.imap
	zip = itertools.izip

def sync_with_stdio(sync=True):
	global input, flush
	if sync:
		flush = sys.stdout.flush
	else:
		sys.stdin = stream(sys.stdin.read())
		input = lambda : sys.stdin.readline().rstrip('\r\n')
		sys.stdout = stream()
		register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))

def main():
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		a = [int(o) for o in input().split()]
		a.sort()
		a = a[::-1]
		su = 0
		for i in range(1, k + 1):
			su += a[i]
		print(su + a[0])
sync_with_stdio(False)
main()


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in [wtf[i:i + 2] for i in range(1, len(wtf), 2)]:
	(n, k) = map(int, t[0].split())
	A = sorted(map(int, t[1].split()), reverse=True)
	print(sum(A[:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a = sorted(a)
	ans = a[n - 1]
	if k > n or k == n:
		k = n - 1
	for j in range(n - 2, n - k - 2, -1):
		ans += a[j]
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst = sorted(lst)
	sol = max(lst)
	nlst = sorted(lst)
	while k > 0:
		sol += nlst[n - 1 - k]
		k -= 1
	print(sol)


for i in range(int(input())):
	b = list(map(int, input().strip().split(' ')))[1] + 1
	a = list(map(int, input().strip().split(' ')))
	a.sort()
	if b != 1:
		print(sum(a[-b:]))
	else:
		print(a[-1] - a[0])


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
INF = float('inf')
mod = 10 ** 9 + 7
for t in range(int(data())):
	(n, k) = mdata()
	a = sorted(mdata(), reverse=True)
	s = sum(a[:k + 1])
	out(s)


x = []
y = 0
a = int(input())
for i in range(0, a):
	(n, b) = list(map(int, input().split()))
	for i in range(n - (n - 1)):
		x = list(map(int, input().split()))
	x = sorted(x)
	for k in range(len(x) - 1, len(x) - 2 - b, -1):
		y = y + x[k]
	print(y)
	y = 0
	del x[:]


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(j) for j in input().split()]
	l.sort(reverse=True)
	c = l[0]
	l = l[1:]
	for i in range(k):
		if l[i] == 0:
			break
		c += l[i]
		l[i] = 0
	print(c - min(l))


import sys
readline = sys.stdin.readline
t = int(readline())
for _ in range(t):
	(n, k) = map(int, readline().split())
	A = list(map(int, readline().split()))
	A.sort()
	ans = A[-1]
	for i in range(k):
		ans += A[-2 - i]
	print(ans)


t = int(input())
for T in range(t):
	i = input()
	lst = list()
	i1 = i.split()
	n = int(i1[0])
	k = int(i1[1])
	j = input()
	i2 = j.split()
	for t in i2:
		lst.append(int(t))
	lst.sort(reverse=True)
	for x in range(k):
		lst[x + 1] += lst[x]
	print(max(lst))


import sys
import math
from functools import reduce
import bisect

def getN():
	return int(input())

def getNM():
	return map(int, input().split())

def getList():
	return list(map(int, input().split()))

def input():
	return sys.stdin.readline().rstrip()

def index(a, x):
	i = bisect.bisect_left(a, x)
	if i != len(a) and a[i] == x:
		return i
	return False

def solve():
	(n, k) = getNM()
	arr = sorted(getList())[::-1]
	ans = 0
	for i in range(k + 1):
		ans += arr[i]
	print(ans)
for _ in range(getN()):
	solve()


import sys
import random
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
input = sys.stdin.readline
getS = lambda : input().strip()
getN = lambda : int(input())
getList = lambda : list(map(int, input().split()))
getZList = lambda : [int(x) - 1 for x in input().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
divide = lambda x: pow(x, MOD - 2, MOD)

def judge(at, ax, ay, bt, bx, by):
	if abs(at - bt) >= abs(ax - bx) + abs(ay - by):
		return True
	else:
		return False

def solve():
	(n, k) = getList()
	li = getList()
	if k >= n:
		print(sum(li))
		return
	li.sort(reverse=True)
	print(sum(li[:k + 1]))
	return

def main():
	n = getN()
	for _ in range(n):
		solve()
	return
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	rs = a[-1]
	cnt = 0
	for i in range(n - 2, -1, -1):
		rs += a[i]
		cnt += 1
		if cnt >= k:
			break
	print(rs)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted([int(i) for i in input().split()])
	x = -2
	for i in range(k):
		if a[x] != 0:
			a[-1] = a[-1] + a[x]
			a[x] = 0
			x = x - 1
	print(max(a) - min(a))


t = int(input())
for _ in range(t):
	nk = input()
	(n, k) = [int(i) for i in nk.split(' ')]
	bs = input()
	bs = [int(i) for i in bs.split(' ')]
	bs.sort()
	for i in range(k):
		bs[-2] += bs[-1]
		bs.pop()
	print(bs[-1])


from sys import stdin, stdout
from math import gcd
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(*a,) = map(int, input().split())
	a.sort(reverse=True)
	for i in range(1, min(n, k + 1)):
		a[0] += a[i]
	print(a[0])


import collections
for t in range(int(input())):
	(n, k) = map(int, input().split())
	nums = sorted(map(int, input().split()))
	if k == 0:
		print(nums[-1] - nums[0])
	elif k >= n:
		print(sum(nums))
	else:
		out = 0
		while k:
			out += nums.pop()
			k -= 1
		print(out + nums[-1])


for i in range(0, int(input())):
	(x, z) = map(int, input().split())
	y = list(map(int, input().split()))
	y.sort()
	print(sum(y[len(y) - z - 1:len(y)]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	capacities = [int(x) for x in input().split()]
	capacities.sort()
	if capacities[n - 1] == 0 or n == 1:
		print(capacities[0])
	else:
		j = n - 2
		for i in range(k):
			if j >= 0:
				capacities[n - 1] += capacities[j]
				capacities[j] = 0
				j -= 1
			else:
				break
		print(capacities[n - 1] - min(capacities))


def main():
	(n, k) = map(int, input().split())
	aa = list(map(int, input().split()))
	aa.sort()
	print(sum(aa[-(k + 1):]))
t = int(input())
for _ in range(t):
	main()


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = sorted(map(int, input().split()), key=int)
	print(sum(l[-k - 1:]))


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		(n, k) = ria()
		a = ria()
		c = min(len(a) - 1, k)
		a = sorted(a)[::-1]
		for i in range(1, c + 1):
			a[0] += a[i]
			a[i] = 0
		print(a[0] - min(a))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for t in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	arr.sort()
	if n == 1:
		print(0)
	else:
		print(sum(arr[-k - 1:]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if k == 0:
		print(arr[n - 1] - arr[0])
	else:
		print(sum(arr[n - k - 1:]))


from collections import deque
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	j = n - 2
	s = 0
	for i in range(k):
		s += arr[j]
		j -= 1
	print(arr[-1] + s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=False)
	ans = 0
	for i in range(n - k - 1, n):
		ans += a[i]
	print(ans)


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	l = 0
	for j in range(min(k + 1, n)):
		l += a[j]
	print(l)


from math import gcd
from sys import stdout, stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, input().split())
	ls = [int(x) for x in input().split()]
	ls = sorted(ls, reverse=True)
	s = 0
	pref = []
	for i in ls:
		s += i
		pref.append(s)
	print(pref[k])


import math
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(100000)

def put():
	return map(int, stdin.readline().split())
for _ in range(int(input())):
	(n, k) = put()
	l = list(put())
	l.sort()
	print(sum(l[-k - 1:]))


Y = lambda : map(int, input().split())
for _ in [0] * next(Y()):
	(n, k) = Y()
	print(sum(sorted(Y())[-1 - k:]))


def solve(A, n, k):
	if n == 1:
		return 0
	if k >= n:
		return sum(A)
	A.sort()
	return sum(A[n - k - 1:])
T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	res = solve(A, n, k)
	print(res)


import sys
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr.sort(reverse=True)
	res = sum(arr[:k + 1])
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	(a, ans) = ([int(num) for num in input().split()], 0)
	a.sort(reverse=True)
	p = 1
	for i in range(k):
		a[0] += a[p]
		a[p] = 0
		p += 1
	print(max(a) - min(a))


for i in range(int(input())):
	(n, k) = map(int, input().split(' '))
	l = sorted(map(int, input().split(' ')))
	sum = l[n - 1]
	for i in range(k):
		sum = sum + l[n - 2 - i]
	print(sum)


k = []
for _ in range(int(input())):
	(n, p) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	k.append(sum(a[:min(n, p + 1)]))
for i in k:
	print(i)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	sumx = 0
	for i in range(k + 1):
		sumx = sumx + arr[n - 1 - i]
	print(sumx)


import sys as _sys

def main():
	t = int(input())
	for i_t in range(t):
		(n, k) = _read_ints()
		a = tuple(_read_ints())
		result = find_max_difference_between_max_and_min(a, k)
		print(result)

def _read_line():
	result = _sys.stdin.readline()
	assert result[-1] == '\n'
	return result[:-1]

def _read_ints():
	return map(int, _read_line().split())

def find_max_difference_between_max_and_min(sequence, operations_n):
	assert operations_n >= 0
	operations_n = min(operations_n, len(sequence) - 1)
	if operations_n == 0:
		return max(sequence) - min(sequence)
	sequence = sorted(sequence)
	curr_max_elem = sequence.pop()
	for i_operation in range(operations_n):
		curr_max_elem += sequence.pop()
	curr_min_elem = 0
	return curr_max_elem - curr_min_elem
main()


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().strip().split()))
	barrels = list(map(int, input().strip().split()))
	barrels.sort()
	if k == 0:
		print(barrels[-1] - barrels[0])
	else:
		sum = barrels[-1]
		for i in range(k):
			sum += barrels[n - i - 2]
		print(sum)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	i = len(a) - 2
	for j in range(0, k):
		a[-1] += a[i]
		a[i] = 0
		i -= 1
	print(abs(max(a) - min(a)))


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	(n, k) = mints()
	a = list(mints())
	a.sort()
	print(sum(a[max(n - k - 1, 0):]))
for i in range(mint()):
	solve()


t = int(input())
for _ in range(t):
	s = input().split()
	(n, k) = (int(s[0]), int(s[1]))
	bi = input().split()
	barrels = []
	for b in bi:
		barrels.append(int(b))
	barrels.sort(reverse=True)
	ans = barrels[0]
	for i in range(1, k + 1):
		if i < n:
			ans += barrels[i]
		else:
			break
	print(ans)


import sys

def In():
	return sys.stdin.readline()

def Out(x):
	return sys.stdout.write(str(x) + '\n')

def solve(arr, k):
	arr.sort(reverse=True)
	if arr[0] == 0:
		return 0
	else:
		for i in range(k):
			arr[0] += arr[1 + i]
		return arr[0]
t = int(In())
for i in range(t):
	(n, k) = map(int, In().split())
	arr = list(map(int, In().split()))
	Out(solve(arr, k))


for i in range(int(input())):
	a = int(input().split()[1])
	print(sum(sorted(list(map(int, input().split())), reverse=True)[:a + 1]))


test_amount = int(input())
for i in range(test_amount):
	(n, k) = tuple(map(int, input().split()))
	bottles = list(map(int, input().split()))
	bottles = sorted(bottles)[::-1]
	for j in range(k):
		if j == len(bottles) - 1:
			break
		bottles[0] += bottles[j + 1]
	print(bottles[0])


import sys, os
from math import sqrt, gcd, ceil, log, floor
from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda : list(map(int, input().strip().split()))
from time import time
MOD = 998244353

def main():
	for _ in range(int(input())):
		(n, k) = read()
		arr = read()
		arr.sort(reverse=True)
		print(sum(arr[:k + 1]))
main()


T = int(input())
for _ in range(0, T):
	(n, k) = map(int, input().split())
	s = [int(x) for x in input().split()]
	s.sort()
	s = s[::-1]
	for i in range(1, min(k + 1, len(s))):
		s[0] += s[i]
	print(s[0])


from collections import *
from functools import *
import math
import sys
inp = sys.stdin.readline
out = sys.stdout.write

def mi():
	return map(int, inp().split())

def li():
	return list(mi())

def ii():
	return int(inp())

def main():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		a.sort(reverse=True)
		for i in range(1, n):
			if k == 0:
				break
			a[0] += a[i]
			a[i] = 0
			k -= 1
		print(max(a) - min(a))
main()


t = int(input())
for _ in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	a = list(map(int, input().split()))
	a.sort()
	max = a[n - 1]
	c = n - 1
	for i in range(k):
		c -= 1
		max = max + a[c]
		if c == 0:
			break
	print(max)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = sorted(map(int, input().split()), reverse=True)
	s = sum(lis[:k + 1])
	print(s)


t = int(input())
for u in range(t):
	ans = 0
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	if arr[0] == arr[-1] == 0:
		print(0)
	else:
		for i in range(0, k + 1):
			ans += arr[n - 1 - i]
		print(ans)


def drink(l, i, j):
	(l[i], l[j]) = (l[i] + l[j], 0)
	return l

def recal(n, k, l):
	l.sort(reverse=True)
	g = 1
	while g <= k:
		l = drink(l, 0, g)
		g += 1
	return l[0] - l[1]
t = int(input())
while t != 0:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(recal(n, k, l))
	t -= 1


for _ in range(int(input())):
	(n, k) = map(int, input().strip().split(' '))
	ar = list(map(int, input().strip().split(' ')))
	ans = 0
	ar.sort(reverse=True)
	for i in range(1, k + 1):
		ans += ar[i]
	print(ans + ar[0])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	array.sort()
	if array[n - 1] == 0:
		print(0)
		continue
	j = 2
	while k:
		array[n - 1] += array[n - j]
		j += 1
		k -= 1
	print(array[n - 1])
	continue


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = sorted(list(map(int, input().split())), reverse=True)
	y = sum(a[:k + 1])
	for i in range(k):
		a[i] = 0
	x = min(a)
	print(y - x)


l = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if k >= n:
		l.append(sum(a))
	else:
		l.append(sum(a[n - k - 1:]))
for i in l:
	print(i)


t = int(input())
q = []
for i in range(t):
	l = list(input().split())
	n = int(l[0])
	k = int(l[1])
	l = list(map(int, list(input().split())))
	l.sort()
	if k == 0:
		q.append(l[-1] - l[0])
		continue
	m = -2
	for j in range(k):
		l[-1] += l[m]
		l[m] = 0
		m -= 1
	q.append(l[-1])
for i in q:
	print(i)


I = lambda : map(int, input().split())
(t,) = I()
exec('n,k=I();*s,=I();print(sum(sorted(s)[~k:]));' * t)


for test_var in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	dif = arr[n - 1]
	ik = k
	while k > 0:
		dif += arr[n - ik + k - 2]
		k -= 1
	print(dif)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	if k == 0:
		print(a[-1] - a[-2])
	else:
		a = a[::-1]
		q = a[0]
		for j in range(1, k + 1):
			q += a[j]
		print(q)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	i = n - 2
	while k and i >= 0:
		arr[-1] += arr[i]
		i -= 1
		k -= 1
	print(arr[-1])


import io, os
R = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, k) = R()
	a = list(R())
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	w = [int(i) for i in input().split()]
	w.sort()
	w.reverse()
	d = 0
	for i in range(k + 1):
		d += w[i]
	print(d)


import math
from collections import deque
from collections import defaultdict
t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().strip().split(' '))
	arr = list(map(int, input().strip().split(' ')))
	arr.sort(reverse=True)
	for i in range(1, n):
		if arr[i] == 0:
			continue
		if k == 0:
			break
		arr[0] += arr[i]
		arr[i] = 0
		k -= 1
	print(max(arr) - min(arr))


for __ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	ar = list(map(int, input().split()))
	ar.sort(reverse=True)
	ans = 0
	for i in range(min(n, k + 1)):
		ans += ar[i]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	l.sort()
	l.reverse()
	print(sum(l[:min(k + 1, n)]))


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	lst = [int(i) for i in input().split()]
	print(sum(sorted(lst)[-k - 1:]))


def solve(n, a, k):
	a.sort()
	return sum(a[n - 1 - k:])
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	print(solve(n, a, k))


def calc(n, k, barrels):
	barrels.sort()
	for i in range(1, k + 1):
		secondLast = barrels[-1 - i]
		barrels[-1 - i] = 0
		barrels[-1] += secondLast
	barrels.sort()
	return barrels[-1] - barrels[0]
trials = int(input())
finals = []
for i in range(trials):
	(n, k) = map(int, input().split())
	barrels = [int(i) for i in input().split()]
	finals.append(calc(n, k, barrels))
for i in finals:
	print(i)


t = int(input())
for i in range(0, t):
	lst = list(map(int, input().split(' ')))
	n = lst[0]
	k = lst[1]
	if 1 <= k and k <= n and (n <= 2 * 10 ** 5):
		list1 = list(map(int, input().split(' ')))
		list1.sort()
		s = list1[-1]
		c = -2
		while k > 0:
			s += list1[c]
			c -= 1
			k -= 1
		print(s)


from sys import stdin, stdout
from collections import Counter
from itertools import permutations
import bisect
import math
I = lambda : map(int, stdin.readline().split())
I1 = lambda : stdin.readline()
for _ in range(int(I1())):
	(n, k) = I()
	a = list(I())
	if set(a) == {0}:
		print(0)
	else:
		a.sort()
		i = n - 2
		while k and i >= 0:
			if a[i] != 0:
				a[n - 1] += a[i]
				a[i] = 0
				i -= 1
				k -= 1
			else:
				i -= 1
		print(max(a) - min(a))


t = int(input())
for tc in range(t):
	(n, k) = map(int, input().split())
	ai = list(map(int, input().split()))
	ai.sort()
	a = ai[::-1]
	diff = a[0]
	for i in range(1, k + 1):
		diff += a[i]
		if a[i] == 0:
			break
	print(diff)


t = int(input())
while t:
	t = t - 1
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort(reverse=True)
	val = 0
	k += 1
	if k == 1:
		print(a[0] - a[n - 1])
		continue
	for i in range(0, k):
		val = val + a[i]
	print(val)
	continue


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr = sorted(arr, reverse=True)
	print(sum(arr[0:k + 1]))


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	k = int(l[1])
	l = input().split()
	li = [int(i) for i in l]
	if k == 0:
		print(max(li) - min(li))
		continue
	z = 0
	li.sort()
	li.reverse()
	for i in range(k + 1):
		z += li[i]
	print(z)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	array.sort()
	sum = 0
	for i in range(n - 1, n - k - 2, -1):
		sum = sum + array[i]
	print(sum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(j) for j in input().split()]
	arr.sort()
	if k == 0:
		print(arr[-1] - arr[0])
	else:
		ans = 0
		for i in range(k + 1):
			ans += arr[-1 - i]
		print(ans)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a.sort(reverse=True)
	maxi = a[0]
	for i in range(1, k + 1):
		maxi += a[i]
	print(maxi)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = sorted(map(int, input().split()))
	i = n - 2
	while i >= 0 and k > 0:
		lis[-1] += lis[i]
		i -= 1
		k -= 1
	print(lis[-1])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	s = sum(A[:k + 1])
	print(s)


import math
import time
from collections import defaultdict, deque, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import PriorityQueue
import sys
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	a.sort(reverse=True)
	if k >= n - 1:
		print(sum(a))
	else:
		for i in range(1, k + 1):
			a[0] += a[i]
			a[i] = 0
		print(max(a) - min(a))


ggg = int(input())
n_all = []
k_all = []
a_all = []
for i in range(0, ggg):
	krokoziabra = input().split()
	n_all.append(int(krokoziabra[0]))
	k_all.append(int(krokoziabra[1]))
	a_all.append(list(map(int, input().split())))
for i in range(0, ggg):
	n = n_all[i]
	k = k_all[i]
	a = a_all[i]
	a.sort()
	nn = n - k - 1
	if nn < 0:
		nn = 0
	print(sum(a[nn:n]))


for t in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	arr.sort(reverse=True)
	ans = arr[0]
	for operation in range(k):
		ans += arr[operation + 1]
	print(ans)


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	(n, k) = mint()
	arr = intl()
	i = 0
	arr.sort(reverse=True)
	for i in range(k):
		arr[0] += arr[i + 1]
	print(arr[0])
for _ in range(iinp()):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if arr[0] == 0:
		print(0)
	else:
		for i in range(k):
			arr[i + 1] += arr[i]
			arr[i] = 0
		print(arr[k])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	if k <= n - 2:
		print(sum(l[-1:-k - 2:-1]))
	else:
		print(sum(l))


from sys import stdin, stdout
import math
from collections import deque
input = stdin.readline

def print(*args, end='\n'):
	s = []
	for i in args:
		s.append(str(i) + ' ')
	s = ''.join(s)
	stdout.write(s + end)

def solve():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	maxx = sum(l[0:k + 1])
	print(maxx)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


t = int(input())
for i in range(t):
	a = []
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	l = len(a)
	for j in range(k):
		a[l - 1] = a[l - 1] + a[l - 1 - (j + 1)]
		a[l - 1 - (j + 1)] = 0
	m = max(a)
	print(m)


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	barrels = list(map(int, input().split()))
	if k >= n:
		print(sum(barrels))
	else:
		barrels = sorted(barrels)
		for i in range(n - 2, n - 2 - k, -1):
			barrels[-1] += barrels[i]
		print(barrels[-1])


def water(arr, k):
	arr = sorted(arr, reverse=True)
	for i in range(1, len(arr)):
		if k != 0:
			arr[0] = arr[0] + arr[i]
			k -= 1
			arr[i] = 0
		if k == 0:
			return arr[0] - min(arr)
t = int(input())
for i in range(t):
	(a, b) = map(int, input().strip().split())
	lst = list(map(int, input().strip().split()))
	print(water(lst, b))


def barrels(nums, k):
	nums = sorted(nums)[::-1]
	if k == 0:
		return nums[0]
	return nums[0] + sum(nums[1:1 + k])
for x in range(int(input())):
	k = int(input().split(' ')[1])
	nums = [x for x in map(int, input().split(' '))]
	print(barrels(nums, k))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	w = list(map(int, input().split()))
	w.sort(reverse=True)
	x = w[0:k + 1]
	print(sum(x))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	ip = sorted(list(map(int, input().split())), reverse=1)
	print(sum(ip[:k + 1]))


t = int(input())
for j in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = max(a)
	b = sorted(a)
	for i in range(n - k - 1, n - 1):
		s += b[i]
	print(s)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	(n, k) = list(map(int, stdin.readline().split()))
	a = list(map(int, stdin.readline().split()))
	a.sort(reverse=True)
	print(sum(a[:1 + k]))


k = int(input())
for i in range(k):
	(n, k) = map(int, input().split())
	aa = list(map(int, input().split()))
	aa.sort(reverse=True)
	if k + 1 >= len(aa):
		print(sum(aa))
		continue
	summa = aa[0]
	for i in range(k):
		summa += aa[i + 1]
	print(summa)


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort()
	for i in range(-2, -n - 1, -1):
		if k == 0:
			break
		a[-1] += a[i]
		a[i] = 0
		k -= 1
	print(a[-1] - min(a))


t = int(input())
for j in range(t):
	(a, b) = map(int, input().split(' '))
	k = list(map(int, input('').split(' ')))
	if k.count(0) == a:
		print(0)
	else:
		k = sorted(k)
		z = max(k)
		for i in range(1, b + 1):
			z += k[a - 1 - i]
		print(z)


t = int(input())
for p in range(t):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort()
	b.reverse()
	print(sum(b[:k + 1]))


for i in range(int(input())):
	(n, k) = [int(i) for i in input().split(' ')]
	arr = [int(i) for i in input().split(' ')]
	arr.sort(reverse=True)
	temp = 0
	for i in range(1, k + 1):
		arr[0] += arr[i]
	print(arr[0])


def readInt():
	return int(input())

def readList():
	return list(map(int, input().split()))

def readMap():
	return map(int, input().split())

def readStr():
	return input()
inf = float('inf')
mod = 10 ** 9 + 7
import math
from itertools import permutations

def solve(N, k, A):
	A.sort(reverse=True)
	if k == 0:
		return A[0] - A[-1]
	for i in range(k):
		A[0] += A[i + 1]
	return A[0]
t = readInt()
for _ in range(t):
	(N, k) = readMap()
	A = readList()
	print(solve(N, k, A))


def helper(arr, l, k):
	arr.sort()
	answer = 0
	for i in range(k + 1):
		if i >= l:
			break
		currentIdx = l - i - 1
		answer = answer + arr[currentIdx]
	return answer
test = int(input())
for i in range(test):
	(l, k) = list(map(int, input().split()))
	inp = list(map(int, input().split()))
	ans = helper(inp, l, k)
	print(ans)


try:
	t = int(input())
	for i in range(0, t):
		(n, k) = list(map(int, input().split(' ')))
		a = list(map(int, input().split(' ')))
		a.sort()
		p = a[len(a) - 1]
		a.pop()
		a.sort(reverse=True)
		for i in range(0, k):
			p += a[i]
		print(p)
except:
	pass


import math
import os
import random
import re
import sys
import functools
from operator import itemgetter, attrgetter
from collections import Counter
t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	print(sum((x for x in a[:k + 1])))


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	c = sorted(list(map(int, input().split())), reverse=True)
	print(sum(c[:b + 1]))


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if k < n:
		print(sum(arr[n - k - 1:]))
	else:
		print(sum(arr))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	ans = 0
	for i in range(-1, -k - 2, -1):
		ans += l[i]
	print(ans)


def solve(n, k, a):
	return sum(sorted(a)[len(a) - k - 1:])
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = solve(n, k, a)
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	if k == 0:
		maxa = max(arr)
		mina = min(arr)
		print(maxa - mina)
		continue
	arr.sort(reverse=True)
	mina = min(k + 1, n)
	sum1 = 0
	for i in range(mina):
		sum1 += arr[i]
	print(sum1)


t = int(input())
for i in range(t):
	data = input().split()
	n = int(data[0])
	k = int(data[1])
	a = [int(i) for i in input().split()]
	a.sort()
	ans = a[n - 1]
	for i in range(n - 2, n - 2 - k, -1):
		ans += a[i]
	print(ans)


t = int(input())
for case in range(1, t + 1):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	s_a = sum(sorted(a)[-(k + 1):])
	print(s_a)


def main():
	t = int(input())
	for _ in range(t):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		a.sort(reverse=True)
		print(sum(a[:k + 1]))
main()


x = int(input())
for z in range(x):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	ans = l[0]
	for i in range(k):
		ans += l[i + 1]
	print(ans)


for j in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	print(sum(l[-k - 1:]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	i = n - 2
	while i >= 0 and k > 0:
		a[-1] += a[i]
		a[i] = 0
		k -= 1
		i -= 1
	print(max(a) - min(a))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	res = a[-1]
	i = 1
	while k > 0:
		res += a[n - i - 1]
		i += 1
		k -= 1
	print(res)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	bars = list(map(int, input().split()))
	if k == 0:
		print(max(bars) - min(bars))
	else:
		print(sum(list(reversed(sorted(bars)))[:k + 1]))


for k in range(int(input())):
	nk = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	result = 0
	for i in range(nk[0] - 1, nk[0] - 2 - nk[1], -1):
		result += a[i]
	print(result)


def ans(n, k, spisok):
	spisok.sort()
	res = spisok[-1]
	for j in range(1, k + 1):
		res += spisok[-1 - j]
	print(res)
t = int(input())
for i in range(t):
	(h, h1) = map(int, input().split())
	h2 = list(map(int, input().split()))
	ans(h, h1, h2)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
from itertools import permutations
MOD = pow(10, 9) + 7
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	l = list(map(int, input().split(' ')))
	l.sort()
	if n == k:
		print(sum(l))
	else:
		ans = l[-1]
		x = min(k, n - 1)
		i = 2
		while x:
			ans += l[n - i]
			x -= 1
			i += 1
		print(ans)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	mx = a[0]
	for i in range(1, k + 1):
		if i >= n:
			break
		mx += a[i]
	print(mx)


def tran(arr, k):
	arr.sort()
	return sum(arr[len(arr) - k - 1:])
t = int(input())
ans = []
for i in range(t):
	nk = list(map(int, input().rstrip().split()))
	arr = list(map(int, input().rstrip().split()))
	r = tran(arr, nk[1])
	ans.append(r)
for i in ans:
	print(i)


def answer(n, k, A):
	if k >= n - 1:
		return sum(A)
	A.sort()
	s = sum(A[n - k - 1:n])
	return s
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(answer(n, k, arr))


for _ in range(int(input())):
	(N, K) = map(int, input().split())
	W = list(map(int, input().split()))
	W.sort()
	for i in range(N - 2, N - 2 - K, -1):
		W[N - 1] += W[i]
	print(W[N - 1])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	lis.sort()
	lis.reverse()
	la = lis[0]
	for i in range(1, k + 1, 1):
		if i < n:
			la += lis[i]
	print(la)


for o in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(list(set(a))) == 1 and list(set(a))[0] == 0:
		print(0)
	elif len(a) == 1:
		print(0)
	elif k == len(a) - 1:
		print(sum(a))
	else:
		a.sort(reverse=True)
		for i in range(n - 1):
			if k == 0:
				break
			else:
				a[0] = a[0] + a[i + 1]
				k = k - 1
		print(a[0])


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	res = sum(a[:k + 1])
	print(res)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	a = list(set(li))
	if a == [0]:
		print(0)
	else:
		li.sort(reverse=True)
		s = sum(li[0:k + 1])
		print(s)


import sys, collections, math, itertools
INF = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 1000000007
for _ in range(int(input())):
	(n, k) = get_ints()
	arr = get_array()
	arr.sort()
	i = n - 2
	cnt = 0
	while i < n:
		arr[-1] += arr[i]
		arr[i] -= arr[i]
		cnt += 1
		if cnt == k:
			break
		i -= 1
	print(max(arr) - min(arr))


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a, reverse=True)
	ans = 0
	if k == 0:
		print(a[0] - a[-1])
	else:
		for i in range(k + 1):
			ans += a[i]
		print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	j = 1
	k = 0
	for i in range(m):
		l[k] += l[j]
		l[j] = 0
		j += 1
	maxs = max(l)
	mins = min(l)
	print(maxs)


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	k = min(k, n - 1)
	print(sum(a[n - 1 - k:]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	out = l[0]
	for i in range(1, m + 1):
		out += l[i]
	print(out)


import sys
t = int(input().strip())
for a0 in range(t):
	l1 = [int(i) for i in input().split()]
	n = l1[0]
	k = l1[1]
	l2 = [int(i) for i in input().split()]
	l2.sort()
	l2.reverse()
	count = 0
	for i in range(k + 1):
		count += l2[i]
	print(count)


t = int(input())
while t:
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	i = n - 2
	while i >= 0 and k > 0:
		a[-1] += a[i]
		a[i] = 0
		i -= 1
		k -= 1
	print(a[-1])
	t -= 1


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	print(sum(l[:-b - 2:-1]))


def void():
	(a, b) = (2, 3)
	return a * b
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	c = l[0]
	l = l[1:]
	for i in range(k):
		if l[i] == 0:
			break
		c += l[i]
		l[i] = 0
	print(c - min(l))


T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	barrels = list(map(int, input().split()))
	barrels.sort()
	cntr = 0
	i = n - 2
	while i >= 0 and cntr < k:
		barrels[-1] += barrels[i]
		barrels[i] = 0
		cntr += 1
		i -= 1
	barrels.sort()
	print(barrels[-1] - barrels[0])


from fractions import Fraction
from decimal import Decimal
import math
mod = pow(10, 9) + 7

def sp():
	return map(int, input().split())

def lit():
	return list(sp())
t = int(input())
for _ in range(t):
	(n, k) = sp()
	l = lit()
	l.sort()
	ma = l[-1]
	mi = l[0]
	if ma == mi:
		print(ma * (k + 1))
	else:
		i = n - 2
		while i >= 0 and k:
			ma += l[i]
			i -= 1
			k -= 1
		print(ma)


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().strip().split()))
	arr.sort()
	arr.reverse()
	mmaxim = max(arr)
	sum = 0
	for i in range(k + 1):
		sum = sum + arr[i]
	print(sum)
	t = t - 1


t = int(input())
while t > 0:
	t -= 1
	li = list(map(int, input().split(' ')))
	n = li[0]
	k = li[1]
	li = list(map(int, input().split(' ')))
	li = sorted(li, reverse=True)
	ans = 0
	for i in range(k + 1):
		ans += li[i]
	print(ans)


t = int(input())
for _ in range(t):
	inp = list(map(int, input().split()))
	k = inp[1]
	arr = list(map(int, input().split()))
	arr.sort()
	ans = arr[-1] + sum(arr[len(arr) - 1 - k:len(arr) - 1])
	print(ans)


from sys import stdin, stdout
import math, sys, heapq
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict
from os import path
import random
import bisect as bi

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def I():
		return int(input())

	def In():
		return map(int, input().split())
else:

	def I():
		return int(stdin.readline())

	def In():
		return map(int, stdin.readline().split())

def dict(a):
	d = {}
	for x in a:
		if d.get(x, -1) != -1:
			d[x] += 1
		else:
			d[x] = 1
	return d

def find_gt(a, x):
	i = bi.bisect_left(a, x)
	if i != len(a):
		return i
	else:
		return -1

def main():
	try:
		(n, k) = In()
		l = list(In())
		cnt = 0
		su = 0
		l.sort(reverse=True)
		temp = []
		for x in range(1, n):
			if l[x] != 0:
				if k:
					su += l[x]
					k -= 1
				else:
					break
		print(l[0] + su)
	except:
		pass
M = 998244353
P = 1000000007
for _ in range(I()):
	main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	s = l[-1]
	i = -2
	while k:
		s += l[i]
		i -= 1
		k -= 1
	print(s)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	x = a[n - 1]
	for i in range(k):
		x += a[n - 2 - i]
	print(x)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
for _ in range(N()):
	(n, k) = RL()
	a = RLL()
	a.sort()
	print(a[-1] + sum(a[-k - 1:-1]))


t = int(input())
res = []
for _ in range(t):
	(n, k) = map(int, input().strip().split(' '))
	a = list(map(int, input().strip().split(' ')))
	a.sort()
	tmp = a[-1]
	for i in range(2, k + 2):
		tmp += a[-1 * i]
	res.append(str(tmp))
print(*res, sep='\n')


def ii():
	return int(input())

def mi():
	return map(int, input().split())
for _ in range(ii()):
	(n, k) = mi()
	ll = sorted(mi())
	if k:
		print(sum(ll[-k - 1:]))
	else:
		print(ll[-1] - ll[0])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort()
	i = -2
	while k:
		b[-1] += b[i]
		b[i] = 0
		i -= 1
		k -= 1
	print(b[-1] - min(b))


ts = int(input())
for t in range(ts):
	(n, k) = [int(i) for i in input().split(' ')]
	l = [int(i) for i in input().split(' ')]
	l = sorted(l)
	m = min(k + 1, n)
	sm = sum(l[n - m:])
	print(sm)


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	list1 = [int(i) for i in input().split()]
	list1.sort(reverse=True)
	for i in range(k):
		list1[0] += list1[i + 1]
		list1[i + 1] = 0
	print(list1[0])


from collections import *
from itertools import *
from bisect import *

def inp():
	return int(input())

def arrinp():
	return [int(x) for x in input().split()]

def main():
	t = inp()
	for _ in range(t):
		(n, k) = arrinp()
		A = arrinp()
		if len(A) == 1:
			print(0)
			continue
		A.sort()
		n = len(A)
		max = A[n - 1]
		i = n - 2
		while k > 0:
			max += A[i]
			i -= 1
			k -= 1
		print(max)
main()


def barrels(n, k, arr):
	if max(arr) == 0:
		return 0
	arr.sort()
	s = 0
	for i in range(n - 2, n - 2 - k, -1):
		s += arr[i]
	return s + arr[-1]
for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(barrels(n, k, arr))


from sys import stdin, stdout
from collections import defaultdict
st = lambda : list(stdin.readline().strip())
li = lambda : list(map(int, stdin.readline().split()))
mp = lambda : map(int, stdin.readline().split())
inp = lambda : int(stdin.readline())
pr = lambda n: stdout.write(str(n) + '\n')
mod = 1000000007
INF = float('inf')

def solve():
	(n, k) = mp()
	l = li()
	if n == 1:
		pr(0)
		return
	l.sort()
	i = n - 2
	while k != 0 and i >= 0:
		l[-1] += l[i]
		l[i] = 0
		i -= 1
		k -= 1
	print(l[-1] - min(l))
for _ in range(inp()):
	solve()


n = int(input())
for i in range(n):
	(m, k) = tuple(map(int, input().split()))
	s = sorted(list(map(int, input().split())))
	s[-1] = s[-1] + sum(s[-1 - k:-1])
	print(s[-1])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	MyList = list(map(int, input().split()))
	MyList.sort()
	(sm, mx2) = (MyList[-1], 0)
	for i in range(len(MyList) - 2, -1, -1):
		sm += MyList[i]
		k -= 1
		if k == 0:
			break
	print(sm)


import math

def fn(a, n, k):
	if n == 1:
		print(a[0])
	if k == 0:
		return a[-1] - a[0]
	c0 = a.count(0)
	if k + c0 >= n - 1:
		return sum(a)
	ans = a[-1]
	for i in range(n - 2, -1, -1):
		if k == 0:
			break
		if a[i] != 0:
			ans += a[i]
			k -= 1
		else:
			break
	return ans
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	print(fn(a, n, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	maxDiff = -1
	if sum(a) == 0:
		print(0)
	elif n == 1:
		print(0)
	else:
		i = n - 2
		j = n - 1
		while i >= 0 and k:
			a[j] += a[i]
			a[i] = 0
			k -= 1
			i -= 1
		print(a[-1])


def solve(n, k, a):
	a.sort(reverse=True)
	upto = min(k, n - 1)
	for i in range(1, upto + 1):
		a[0] += a[i]
	return a[0]
t = int(input())
ns = []
ks = []
aa = []
for _ in range(t):
	(n, k) = map(int, input().split())
	ns.append(n)
	ks.append(k)
	a = list(map(int, input().split()))
	aa.append(a)
for i in range(t):
	print(solve(ns[i], ks[i], aa[i]))


T = int(input())
for i in range(T):
	(N, K) = list(map(int, input().split()))
	L = list(map(int, input().split()))
	L.sort()
	Sum = sum(L[N - K - 1:])
	print(Sum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	x = max(l1)
	l1.sort()
	l2 = l1[0:n - 1]
	if x == 0:
		print(0)
	else:
		l2.sort()
		z = l2.count(0)
		l3 = l2[0 + z:len(l2)]
		l3.sort(reverse=True)
		ans = x
		y = len(l3)
		if k <= y:
			for i in range(k):
				ans += l3[i]
			print(ans)
		else:
			for i in range(y):
				ans += l3[i]
			print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	print(sum(arr[:-k - 2:-1]))


import sys
from collections import deque
from copy import *

def eprint(*args):
	print(*args, file=sys.stderr)
zz = 1
if zz:
	input = sys.stdin.readline
else:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('all.txt', 'w')
di = [[-1, 0], [1, 0], [0, 1], [0, -1]]

def string(s):
	return ''.join(s)

def fori(n):
	return [fi() for i in range(n)]

def inc(d, c, x=1):
	d[c] = d[c] + x if c in d else x

def bo(i):
	return ord(i) - ord('A')

def li():
	return [int(xx) for xx in input().split()]

def fli():
	return [float(x) for x in input().split()]

def comp(a, b):
	if a > b:
		return 2
	return 2 if a == b else 0

def gi():
	return [xx for xx in input().split()]

def cil(n, m):
	return n // m + int(n % m > 0)

def fi():
	return int(input())

def pro(a):
	return reduce(lambda a, b: a * b, a)

def swap(a, i, j):
	(a[i], a[j]) = (a[j], a[i])

def si():
	return list(input().rstrip())

def mi():
	return map(int, input().split())

def gh():
	sys.stdout.flush()

def isvalid(i, j):
	return 0 <= i < n and 0 <= j < m and (a[i][j] != '.')

def bo(i):
	return ord(i) - ord('a')

def graph(n, m):
	for i in range(m):
		(x, y) = mi()
		a[x].append(y)
		a[y].append(x)
t = fi()
while t > 0:
	t -= 1
	(n, k) = mi()
	a = li()
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math
import threading
import sys
import time

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def solve():
	(n, k) = get_tuple()
	ls = get_list()
	ls.sort(reverse=True)
	i = 1
	while i < n and k > 0:
		k -= 1
		ls[0] += ls[i]
		i += 1
	print(ls[0])

def main():
	solve()
TestCases = True
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


from sys import stdin, stdout
import heapq

def II():
	return int(stdin.readline())

def MI():
	return map(int, stdin.readline().split())

def LI():
	return list(map(int, stdin.readline().split()))

def solve():
	(n, k) = MI()
	a = LI()
	a = [-i for i in a]
	ans = 0
	heapq.heapify(a)
	for i in range(k + 1):
		v = heapq.heappop(a)
		if v == 0:
			break
		ans -= v
	stdout.write(str(ans) + '\n')
t = II()
for _ in range(t):
	solve()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(x) for x in input().split()]
	var = n - 2
	l.sort()
	last = l[n - 1]
	for i in range(k):
		last += l[var]
		var -= 1
	print(last)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	sum = 0
	for i in a[n - k - 1:n]:
		sum += i
	print(sum)


t = int(input())
for i in range(t):
	L = list()
	(n, k) = map(int, input().split(' '))
	ch = input()
	L = ch.split(' ')
	L = [int(j) for j in L]
	L.sort()
	L.sort(reverse=True)
	L1 = [L[j] for j in range(0, k + 1)]
	print(sum(L1))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	x = sorted(a)
	sum = x[n - 1]
	p = 1
	while p < k + 1:
		sum += x[n - 1 - p]
		p += 1
	print(sum)


for i in range(int(input())):
	(n, k) = [int(num) for num in input().split()]
	count = 0
	x = list(map(int, input().split()))
	x.sort(reverse=True)
	for i in range(k + 1):
		count = count + x[i]
	print(count)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	p = a[::-1]
	print(sum(p[:k + 1]))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	for i in range(n - k - 1, n - 1):
		arr[n - 1] += arr[i]
	print(arr[n - 1])
	t -= 1


def sufferu(l, k):
	l.sort()
	x = l[-1]
	l1 = l[::-1][1:]
	i = 0
	while k > 0 and i < len(l1):
		if l1[i] != 0:
			x += l1[i]
			k -= 1
		i += 1
	return x
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(sufferu(l, k))


from collections import Counter
import math
import sys
from bisect import bisect, bisect_left, bisect_right
from itertools import permutations

def input():
	return sys.stdin.readline().strip()

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def mod():
	return 10 ** 9 + 7
for i in range(INT()):
	(n, k) = MAP()
	a = LIST()
	a = sorted(a, reverse=True)
	ans = a[0]
	for i in range(1, k + 1):
		ans += a[i]
	print(ans)


def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s)])

def invr():
	return map(int, input().split())
n = inp()
for i in range(n):
	l = inlt()
	k = l[1]
	l = inlt()
	l.sort()
	large = l[-k - 1:]
	print(sum(large))


t1 = int(input())
for _ in range(t1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	p = a[0]
	for i in range(1, k + 1):
		p += a[i]
	if p == 0:
		print(max(a) - min(a))
	else:
		print(p)


for _ in range(int(input())):
	(a, b) = map(int, input().split())
	S = list(map(int, input().split()))
	S = sorted(S)
	t = -2
	ans = S[-1]
	for i in range(b):
		ans += S[t]
		t -= 1
	print(ans)


from math import *
from cmath import *
from itertools import *
from decimal import *
from fractions import *
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort(reverse=True)
	sum = 0
	for x in range(min(k + 1, n)):
		sum += a[x]
	print(sum)


n = int(input())
for i in range(n):
	(p, k) = map(int, input().split())
	b = sorted(list(map(int, input().split())))
	print(sum(b[-k - 1:]))


from sys import stdin, stdout
input = stdin.readline
print = lambda x: stdout.write(str(x) + '\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	s = sum(a[:k + 1])
	print(s)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	for i in range(1, k + 1):
		l[0] = l[i] + l[0]
		l[i] = 0
	print(max(l) - min(l))


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def rinput():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))
mod = int(1000000000.0) + 7
for _ in range(iinput()):
	(n, k) = rinput()
	a = get_list()
	a.sort()
	for i in range(1, k + 1):
		a[-1] += a[n - i - 1]
		a[n - i - 1] = 0
	print(max(a) - min(a))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	cnt = sum(a[1:k + 1])
	a[0] += cnt
	print(a[0])


def cal(a, k, length):
	if length == 1:
		return 0
	a.sort()
	index = length - 2
	while k > 0:
		a[-1] = a[-1] + a[index]
		index -= 1
		k -= 1
	return a[-1]
ans = []
c = int(input())
for i in range(c):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans.append(cal(a, k, n))
for i in ans:
	print(i)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	i = n - 1
	asn = l[-1] - l[0]
	while k > 0 and i > 0:
		l[i - 1] += l[i]
		l[i] = 0
		ans = l[i - 1]
		k -= 1
		i -= 1
	print(ans)


T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	print(sum(A[:K + 1]))


import sys
from collections import defaultdict as dd
from collections import Counter as cc
from queue import Queue
import math
import itertools
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
input = lambda : sys.stdin.buffer.readline().rstrip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	l = 0
	for i in range(1, k + 2):
		l += a[-i]
	print(l)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	l = max(a)
	for i in range(k):
		l += a[n - 2 - i]
		a[n - 2 - i] = 0
	print(l - min(a))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	print(sum(a[0:min(len(a), k + 1)]))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	ans = arr[0]
	for j in range(1, k + 1):
		ans += arr[j]
	print(ans)


for i in range(int(input())):
	(a, b) = map(int, input().split())
	c = list(map(int, input().split()))
	c = sorted(c, reverse=True)
	d = max(c)
	if max(c) == 0:
		print(0)
	else:
		for x in range(b):
			d = d + c[x + 1]
		print(d)


def fun(ls, k):
	k = k + 1
	lt = sorted(ls)[::-1]
	ans = 0
	count = 0
	for i in lt:
		ans += i
		count += 1
		if count >= k:
			break
	print(ans)
T = int(input())
for i in range(T):
	(n, k) = list(map(int, input().split()))
	ls = list(map(int, input().split()))
	fun(ls, k)


def solve(n, k, a):
	a.sort(reverse=True)
	if k >= n - 1:
		return sum(a)
	s = a[0]
	for i in range(1, k + 1):
		s += a[i]
	return s
noOfTestCases = int(input())
for i in range(noOfTestCases):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	ans = solve(n, k, a)
	print(ans)


for _ in range(int(input())):
	(n, k) = input().split(' ')
	arr = [int(x) for x in input().split(' ')]
	arr.sort()
	arr.reverse()
	print(sum(arr[:int(k) + 1]))


for t in range(int(input())):
	(n, k) = [int(n) for n in input().split()]
	a = [int(i) for i in input().split()]
	(ans, y) = (0, 0)
	if sum(a) < 1:
		ans = 0
	else:
		a = sorted(a, reverse=True)
		ans = sum(a[:k + 1])
	print(ans)


t = int(input())
w = []
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	if n - 1 <= k:
		w.append(sum(arr))
	else:
		for i in range(k):
			arr[-1] = arr[-1] + arr[n - 2 - i]
		w.append(arr[-1])
for i in w:
	print(i)


import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	for i in range(k):
		if n - 2 - i == -1:
			break
		a[-1] += a[n - 2 - i]
		a[n - 2 - i] = 0
	print(max(a) - min(a))


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def modefiedSieve():
	mx = 10 ** 7 + 1
	sieve = [-1] * mx
	for i in range(2, mx):
		if sieve[i] == -1:
			sieve[i] = i
			for j in range(i * i, mx, i):
				if sieve[j] == -1:
					sieve[j] = i
	return sieve

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def solve():
	(n, k) = num_input()
	arr = sorted(list_input())
	if n == 1:
		print(arr[0])
		return
	indx = n - 2
	for i in range(k):
		arr[-1] += arr[indx]
		indx -= 1
	print(arr[-1])
t = 1
t = int(input())
for _ in range(t):
	solve()


import sys, math
input = sys.stdin.readline
t = int(input())
for r in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	ans = 0
	for i in range(k + 1):
		ans += l[i]
	print(ans)


n1 = int(input())
for z in range(n1):
	(n, k) = map(int, input().split(' '))
	b = list(map(int, input().split()))
	b.sort()
	for i in range(n - 2, -1, -1):
		if k == 0:
			break
		b[n - 1] += b[i]
		k -= 1
	print(b[n - 1])


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, K, A):
	A.sort()
	return sum(A[N - (K + 1):])
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
TC = int(input())
for tc in range(1, TC + 1):
	(N, K) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, K, A)
	print(ans)


import math
t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	if n == 1:
		print('0')
		continue
	ans = A[0]
	for i in range(1, n):
		ans += A[i]
		if i == k:
			break
	print(ans)


import sys, math, cmath, time, collections
start_time = time.time()

def solve():
	(n, k) = invr()
	a = inlt()
	a.sort(reverse=True)
	print(sum(a[1:k + 1]) + a[0])

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


R = lambda : map(int, input().split())
for i in range(int(input())):
	(n, k) = R()
	print(sum(sorted(R())[~k:]))


for test in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	if len(arr) == 1:
		print(0)
		continue
	i = len(arr) - 2
	while k > 0 and i > -1:
		arr[-1] += arr[i]
		i -= 1
		k -= 1
	print(arr[-1])


t = int(input())
for x in range(t):
	s = input()
	s1 = s.split()
	n = int(s1[0])
	k = int(s1[1])
	s = input()
	s1 = s.split()
	l = [int(i) for i in s1]
	import heapq
	heap = []
	heapq.heapify(heap)
	for i in l:
		heapq.heappush(heap, -i)
	sum1 = 0
	for i in range(k + 1):
		sum1 = sum1 - heapq.heappop(heap)
	print(sum1)


f = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, k) = f()
	a = list(f())
	a = sorted(a, reverse=True)
	if k > n:
		print(sum(a))
	else:
		a = a[:k + 1]
		print(sum(a))


for test in range(int(input())):
	[n, k] = list(map(int, input().split(' ')))
	a = list(map(int, input().split(' ')))
	if k == 0:
		print(max(a) - min(a))
	else:
		a.sort(reverse=True)
		print(sum(a[0:k + 1]))


from math import ceil
from sys import stdin, stdout, setrecursionlimit
from random import randint
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	print(sum(sorted([int(i) for i in input().split()], reverse=True)[:k + 1]))


import time, math as mt, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
from collections import OrderedDict
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count
mx = 10 ** 7
spf = [mx] * (mx + 1)

def SPF():
	spf[1] = 1
	for i in range(2, mx + 1):
		if spf[i] == mx:
			spf[i] = i
			for j in range(i * i, mx + 1, i):
				if i < spf[j]:
					spf[j] = i
	return

def readTree(v):
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return adj

def solve():
	(n, k) = IP()
	a = L()
	a.sort()
	if k == 0:
		print(a[-1] - a[0])
		return
	ans = a[-1]
	for i in range(n - 2, -1, -1):
		if k > 0:
			ans += a[i]
			k -= 1
		else:
			break
	print(ans)
	return
t = II()
for i in range(t):
	solve()


for i in range(int(input())):
	info = list(map(int, input().split()))
	(n, k) = (info[0], info[1])
	lst = sorted(list(map(int, input().split())))
	max = 0
	while k != 0:
		k -= 1
		max -= 1
		lst[-1] += lst[max - 1]
	print(lst[-1])


t = int(input())
for i in range(0, t):
	(k, m) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	s = sum(a[:m + 1])
	print(s - 0)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	s = sum(sorted(a)[-k - 1:])
	print(s)


_ = int(input())

def main():
	for __ in range(_):
		line = input()
		tmp = line.split(' ')
		(n, k) = (int(tmp[0]), int(tmp[1]))
		line = input()
		tmp = line.split(' ')
		arr = [int(i) for i in tmp]
		arr = sorted(arr, reverse=True)
		tmp = arr[:k + 1]
		print(sum(tmp))
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	a = a[::-1]
	print(sum(a[:min(k + 1, n)]))


for tc in [0] * int(input()):
	[n, k] = list(map(int, input().split(' ')))
	lis = list(map(int, input().split(' ')))
	su = 0
	i = 1
	if set(lis) == {0}:
		print(0)
	else:
		lis1 = lis.sort(reverse=True)
		su = lis[0]
		while k:
			su = su + lis[i]
			i = i + 1
			k -= 1
		print(su)


for z in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()), reverse=True)
	for i in range(1, min(n, k + 1)):
		a[0] += a[i]
	print(a[0])


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
for _ in range(Int()):
	(n, k) = value()
	a = sorted(array(), reverse=True)
	ans = a[0]
	a = a[1:]
	ans += sum(a[:k])
	print(ans)


t = int(input())
while t:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	arr.reverse()
	b = arr[0]
	arr.pop(0)
	for i in range(k):
		b += arr[i]
		arr[i] = 0
	print(b - min(arr))
	t -= 1


from collections import defaultdict
T = int(input())
for t in range(T):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = a[-1]
	i = 0
	if n == 1:
		print(ans)
		continue
	for i in range(k):
		if a[n - i - 2] == 0:
			break
		ans += a[n - i - 2]
	print(ans)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
num = int(z())
for _ in range(num):
	(n, k) = zz()
	arr = szzz()
	if k >= n:
		print(sum(arr))
		continue
	ans = arr[-1]
	i = 2
	for _ in range(k):
		ans += arr[-i]
		i += 1
	print(ans)


def barrels():
	test_cases = int(input())
	for t in range(test_cases):
		(n, k) = [int(x) for x in input().split(' ')]
		arr = [int(x) for x in input().split(' ')]
		arr.sort(reverse=True)
		if k == 0:
			print(arr[0] - arr[len(arr) - 1])
		else:
			print(sum(arr[:k + 1]))
barrels()


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	barrels = sorted(list(map(int, input().split())), reverse=True)
	i = 1
	while k and i < n:
		if barrels[i] != 0:
			barrels[0] += barrels[i]
			barrels[i] = 0
		i += 1
		k -= 1
	print(barrels[0] - min(barrels))


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def main():
	try:
		for _ in range(inp()):
			(n, k) = invr()
			a = sorted(inlt(), reverse=True)
			print(sum(a[:k + 1]))
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	flag = False
	arr.sort()
	if arr[-1] == 0:
		print(0)
	else:
		l = n - 1
		idx = n - 2
		while k != 0:
			if idx >= 0 and arr[idx] != 0:
				arr[l] += arr[idx]
				idx -= 1
				k -= 1
			else:
				print(arr[l])
				flag = True
				break
		if flag == False:
			print(arr[l])


t = int(input())
for i in range(t):
	n = [int(x) for x in input().split()]
	k = n[1]
	n = n[0]
	a = [int(x) for x in input().split()]
	a = sorted(a, reverse=True)
	for j in range(1, k + 1):
		a[0] += a[j]
		a[j] = 0
	print(a[0])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	y = list(map(int, input().split()))[:n]
	y.sort()
	y.reverse()
	sum = 0
	r = 0
	for i in y:
		if r <= k:
			sum = sum + i
			r += 1
	print(sum)


for t in range(int(input())):
	(n, k) = map(int, input().strip().split())
	arr = list(map(int, input().strip().split()))
	i = 1
	if sum(arr) == 0:
		print(0)
	else:
		arr.sort(reverse=True)
		max_diff = 0
		while i < k + 1:
			arr[0] += arr[i]
			arr[i] = 0
			max_diff = arr[0] - arr[i]
			i += 1
		print(max_diff)


t = int(input(''))
for _ in range(t):
	[n, k] = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if arr[0] == 0:
		print(0)
		continue
	if k == 0:
		print(arr[0] - arr[n - 1])
		continue
	mx = arr[0]
	for i in range(1, n):
		if arr[i] != 0 and k:
			mx += arr[i]
			arr[i] = 0
			k -= 1
		if k <= 0:
			break
	print(mx)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	last = n - 2
	for i in range(k):
		if last < 0:
			break
		else:
			a[-1] += a[last]
			a[last] = 0
			last -= 1
	print(a[-1])


import os
import sys
from io import BytesIO, IOBase
import math

def main():
	pass
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def binary(n):
	return bin(n).replace('0b', '')

def decimal(s):
	return int(s, 2)

def pow2(n):
	p = 0
	while n > 1:
		n //= 2
		p += 1
	return p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(int(n))
	return l

def isPrime(n):
	if n == 1:
		return False
	else:
		root = int(n ** 0.5)
		root += 1
		for i in range(2, root):
			if n % i == 0:
				return False
		return True

def maxPrimeFactors(n):
	maxPrime = -1
	while n % 2 == 0:
		maxPrime = 2
		n >>= 1
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			maxPrime = i
			n = n / i
	if n > 2:
		maxPrime = n
	return int(maxPrime)

def countcon(s, i):
	c = 0
	ch = s[i]
	for i in range(i, len(s)):
		if s[i] == ch:
			c += 1
		else:
			break
	return c
for xyz in range(0, int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	l = l[::-1]
	print(sum(l[0:k + 1]))


import math
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if arr[0] == 0:
		print(0)
	elif k >= n:
		print(sum(arr))
	else:
		for i in range(0, k):
			arr[0] += arr[i + 1]
			arr[i + 1] = 0
		print(arr[0])


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()
import sys
input = sys.stdin.readline
scanner = lambda : int(input())
string = lambda : input().rstrip()
get_list = lambda : list(read())
read = lambda : map(int, input().split())
get_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def is_integer(n):
	return math.ceil(n) == math.floor(n)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True

def next_prime(n, primes):
	while primes[n] != True:
		n += 1
	return n
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(moves, n):
	val = (moves + 1) // 2
	rem = moves - val
	sol = (val + 1) * (rem + 1)
	return sol < n

def sortSecond(val):
	return val[1]
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
alphs = 'abcdefghijklmnopqrstuvwxyz'
from itertools import permutations
import math
import bisect as bis
import random
import sys
import collections as collect
import functools as fnt
from decimal import Decimal

def solve():
	(n, k) = read()
	barrels = get_list()
	barrels.sort()
	for i in range(n - 2, -1, -1):
		if barrels[i] > 0 and k > 0:
			barrels[-1] += barrels[i]
			barrels[i] = 0
			k -= 1
	print(barrels[-1])
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
t = scanner()
for i in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	array.sort()
	array.reverse()
	array[0] += sum(array[1:k + 1])
	print(max(array))


t = int(input())
for q in range(t):
	ch = input()
	L = [int(i) for i in ch.split()]
	(n, k) = (L[0], L[1])
	ch = input()
	L = [int(i) for i in ch.split()]
	L.sort(reverse=True)
	nb = 0
	for i in range(k + 1):
		nb += L[i]
	print(nb)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	maxx = a[0]
	minn = a[-1]
	i = 1
	cnt = 0
	left = 0
	while i < n and cnt < k:
		left = left + a[i]
		a[i] = 0
		cnt = cnt + 1
		i += 1
	print(maxx + left - min(a))


import sys
import math

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	(n, k) = get_ints()
	b = get_array()
	a = sorted(b)[::-1]
	ans = [a[0]]
	for i in range(1, k + 1):
		ans.append(ans[-1] + a[i])
	print(max(ans))


def lis():
	return [int(x) for x in input().split()]

def intt():
	return int(input())
t = intt()
for i in range(t):
	(n, k) = lis()
	a = lis()
	a.sort()
	if k == n - 1:
		print(sum(a))
	else:
		print(sum(a[n - k - 1:n]))


def solve():
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	lst.sort()
	ans = 0
	for i in range(n - k - 1, n):
		ans += lst[i]
	print(ans)
for i in range(int(input())):
	solve()


test_num = int(input())
while test_num:
	(n, k) = map(int, input().split())
	barrel = [int(x) for x in input().split()]
	barrel.sort(reverse=True)
	if barrel[0] == 0:
		print(0)
		test_num = test_num - 1
	else:
		for i in range(k):
			barrel[0] += barrel[i + 1]
		print(barrel[0])
		test_num = test_num - 1


t = int(input())
for _ in range(t):
	nk = list(map(int, input().rstrip().split()))
	n = nk[0]
	k = nk[1]
	a = list(map(int, input().rstrip().split()))
	a = sorted(a)
	for i in range(k):
		a[n - 1] += a[n - 2 - i]
	print(a[n - 1])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	i = 0
	j = 1
	while i < k and j < n:
		l[0] += l[j]
		l[j] = 0
		j = j + 1
		i = i + 1
	print(max(l) - min(l))


for i in range(int(input())):
	(a, b) = list(map(int, input().split(' ')))
	c = list(map(int, input().split(' ')))
	d = sorted(c)
	e = sum(d)
	for j in range(a - b - 1):
		e = e - d[j]
	print(e)


import sys
t = int(input())
while t > 0:
	t -= 1
	input = sys.stdin.readline()
	(n, k) = map(int, input.split())
	input = sys.stdin.readline()
	ar = list(map(int, input.split()))
	ar.sort()
	ar.reverse()
	if ar[0] == 0:
		print(0)
	elif k == 0:
		print(ar[0] - ar[-1])
	else:
		ans = ar[0]
		for i in range(k):
			ans += ar[i + 1]
		print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if len(set(a)) == 1:
		if 0 in a:
			print(0)
		else:
			print(a[0] * (k + 1))
	else:
		a.sort(reverse=True)
		ele = a[0]
		a = a[1:]
		for i in range(k):
			if a[i] == 0:
				break
			ele += a[i]
			a[i] = 0
		print(ele - min(a))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = [int(i) for i in input().split()]
	l.sort(reverse=True)
	m = l[0]
	m += sum(l[1:k + 1])
	print(m)


from sys import stdin

def barrels(k, a):
	(score, *a) = sorted(a)[::-1]
	for i in range(k):
		if i > len(a) - 1:
			break
		score += a[i]
	print(score)
t = int(stdin.readline())
cases = []
for _ in range(t):
	(n, k) = (int(s) for s in stdin.readline().split())
	a = [int(s) for s in stdin.readline().split()]
	cases.append((k, a))
for c in cases:
	barrels(*c)


import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log2, ceil
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
from bisect import insort
from collections import Counter
from collections import deque
from heapq import heappush, heappop, heapify
from itertools import permutations, combinations
mod = int(1000000000.0) + 7
ip = lambda : int(stdin.readline())
inp = lambda : map(int, stdin.readline().split())
ips = lambda : stdin.readline().rstrip()
out = lambda x: stdout.write(str(x) + '\n')
t = ip()
for _ in range(t):
	(n, k) = inp()
	arr = list(inp())
	arr.sort()
	for i in range(n - 2, -1, -1):
		if k == 0:
			break
		else:
			arr[n - 1] += arr[i]
			arr[i] = 0
			k -= 1
	ans = arr[n - 1] - min(arr)
	out(ans)


for _ in range(int(input())):
	result = 0
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))[::-1]
	for i in range(k + 1):
		result += a[i]
	print(result)


n = int(input())
for i in range(n):
	l = []
	(n, k) = map(int, input().split())
	ai = list(map(int, input().split()))
	l = ai
	l.sort()
	a = 1
	while a <= n - 1 and k > 0:
		l[n - 1] += l[n - a - 1]
		a += 1
		k -= 1
	print(l[n - 1])


from sys import stdin, stdout
import math, sys
from itertools import permutations, combinations
from collections import defaultdict, deque, OrderedDict, Counter
from os import path
import bisect as bi
import heapq
mod = 10 ** 9 + 7

def yes():
	print('YES')

def no():
	print('NO')
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

	def inp():
		return int(input())

	def minp():
		return map(int, input().split())
else:

	def inp():
		return int(stdin.readline())

	def minp():
		return map(int, stdin.readline().split())
for _ in range(inp()):
	(n, k) = minp()
	a = list(minp())
	a.sort()
	if k == 0:
		print(a[n - 1] - a[0])
		continue
	count = 0
	for i in range(n - 2, n - 2 - k, -1):
		count += a[i]
	print(count + a[n - 1])


inp = lambda : int(input())
strl = lambda : list(input().strip())
seq = lambda : list(map(int, input().strip().split()))

def results(arr, n, k):
	arr.sort(reverse=True)
	return sum(arr[:k + 1])

def main():
	t = inp()
	for _ in range(t):
		nk = seq()
		(n, k) = (nk[0], nk[1])
		a = seq()
		result = results(a, n, k)
		print(result)
main()


t = int(input())
answers = []
for _ in range(t):
	nk = input().split()
	a = input().split()
	a_mod = []
	for i in range(int(nk[0])):
		a_mod.append(int(a[i]))
	a_mod.sort(reverse=True)
	x = sum(a_mod[:int(nk[1]) + 1])
	answers.append(x)
for j in range(t):
	print(answers[j])


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from math import gcd, factorial, floor, ceil
from copy import deepcopy
from collections import deque
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 10 ** 9 + 7

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p) + ': ', end='')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	(n, k) = sep()
	a = sorted(lis())
	ans = a[n - 1]
	i = n - 2
	for _ in range(k):
		ans += a[i]
		i -= 1
	print(ans)
testcase(int(inp()))


import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return [int(i) for i in input().split()]

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	new_number = 0
	while number > 0:
		new_number += number % base
		number //= base
	return new_number

def cdiv(n, k):
	return n // k + (n % k != 0)

def ispal(s):
	for i in range(len(s) // 2 + 1):
		if s[i] != s[-i - 1]:
			return False
	return True
for _ in range(ii()):
	(n, k) = mi()
	a = sorted(li())
	print(sum(a[n - k - 1:]))


from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	s = sum(arr[:k])
	print(arr[k] + s)


input = __import__('sys').stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	s = sorted(map(int, input().split()))
	i = n - 2
	for _ in range(k):
		s[-1] += s[i]
		s[i] = 0
		i -= 1
	print(max(s) - min(s))


import sys
input = sys.stdin.readline

def solveB(xs, k):
	if len(xs) == 1:
		return 0
	xs = sorted(xs)
	return sum(xs[-k - 1:])
t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	xs = [int(x) for x in input().split()]
	print(solveB(xs, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	for i in range(k):
		a[-1] += a[-2 - i]
	print(a[-1])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	a = sorted(arr)[::-1]
	ans = a[0]
	for i in range(1, k + 1):
		ans += a[i]
	print(ans)


t1 = int(input())
for z in range(t1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	print(sum(a[0:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	sum = l[0]
	if k == 0:
		print(l[0] - l[n - 1])
	else:
		for j in range(1, k + 1):
			sum += l[j]
		print(sum)


from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from fractions import Fraction
from decimal import Decimal
import math
mod = pow(10, 9) + 7

def sp():
	return map(int, input().split())

def lit():
	return list(sp())

def fun(x):
	return sum((int(i) for i in str(x)))

def find(n):
	if n == 3:
		return 3
	while 1:
		flag = 0
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				n += 1
				break
			if i == int(sqrt(n)):
				flag = 1
				break
		if flag:
			break
	return n
t = int(input())
for _ in range(t):
	(n, k) = sp()
	l = lit()
	l.sort()
	ma = l[-1]
	mi = l[0]
	if ma == mi:
		print(ma * (k + 1))
	else:
		i = n - 2
		while i >= 0 and k:
			ma += l[i]
			i -= 1
			k -= 1
		print(ma)


a = int(input())
for i in range(a):
	(b, c) = map(int, input().split())
	d = list(map(int, input().split()))
	d.sort()
	print(sum(d[-c - 1:]))


from sys import stdin, stdout
input = stdin.readline
from collections import defaultdict as dd
import math

def geti():
	return map(int, input().strip().split())

def getl():
	return list(map(int, input().strip().split()))

def gets():
	return input()

def geta():
	return int(input())

def print_s(s):
	stdout.write(s + '\n')

def solve():
	for _ in range(geta()):
		(n, k) = geti()
		a = getl()
		a.sort()
		if n == 1:
			print(0)
			continue
		for i in range(n - 2, -1, -1):
			if k == 0:
				break
			a[-1] += a[i]
			a[i] = 0
			k -= 1
		print(max(a) - min(a))
solve()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	i = 1
	while k and i < n:
		if a[-1 - i] != 0:
			a[-1] += a[-1 - i]
			a[-1 - i] = 0
			k -= 1
		i += 1
	print(a[-1] - min(a))


import sys
import math as mt
import bisect
input = sys.stdin.readline
t = int(input())
import collections
import heapq
p = 10 ** 9 + 7

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	l.sort(reverse=True)
	l1 = []
	for i in range(1, len(l)):
		l1.append(l[i])
	maxi = l[0]
	mini = min(l[1:])
	for i in range(min(k, len(l1))):
		maxi += l1[i]
		mini = 0
	return maxi - mini
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	print(solve())


from __future__ import division
from sys import stdin, stdout
from collections import deque, defaultdict, Counter
rstr = lambda : stdin.readline().strip()
rstrs = lambda : [str(x) for x in stdin.readline().split()]
rint = lambda : int(stdin.readline())
rints = lambda : [int(x) for x in stdin.readline().split()]
rstr_2d = lambda n: [rstr() for _ in range(n)]
rint_2d = lambda n: [rint() for _ in range(n)]
rints_2d = lambda n: [rints() for _ in range(n)]
pr = lambda args, sep: stdout.write(sep.join(map(str, args)) + '\n')
out = []
for _ in range(int(input())):
	(n, k) = rints()
	a = sorted(rints())
	for j in range(n - 2, -1, -1):
		if not k:
			break
		a[-1] += a[j]
		k -= 1
	out.append(a[-1])
print('\n'.join(map(str, out)))


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ans = a.pop()
	a.sort(reverse=True)
	for i in range(k):
		ans += a[i]
	print(ans)
	return
t = int(input())
for _ in range(t):
	solve()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	s.sort(reverse=True)
	print(sum(s[:k + 1])) if k <= n else sum(s)


t = int(input())
result = []
for _ in range(t):
	(n, k) = map(int, input().split())
	if n == 1:
		result.append(0)
		continue
	aa = list(map(int, input().split()))
	aa.sort()
	result.append(sum(aa[-(k + 1):]))
for r in result:
	print(r)


TC = int(input())
for l in range(TC):
	(n, k) = (int(x) for x in input().split())
	L = [int(x) for x in input().split()]
	L = sorted(L)
	for i in range(k):
		L[n - 1] += L[n - 2 - i]
	print(L[n - 1])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr.sort()
	max_v = sum(arr[n - k - 1:n - 1]) + arr[-1]
	min_v = 0
	print(max_v - min_v)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	if k == 0:
		print(max(A) - min(A))
	else:
		print(A[0] + sum(A[1:k + 1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	m1 = l[-1]
	if n == 1:
		print(0)
	elif n == 2:
		if k > 0:
			print(l[1] + l[0])
		else:
			print(l[1] - l[0])
	else:
		for i in range(k):
			m1 += l[n - i - 2]
		print(m1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	while k != 0:
		l[n - 1] += l[n - 1 - k]
		l[n - 1 - k] = 0
		k -= 1
	print(max(l) - min(l))


q = int(input())
for _ in range(q):
	(n, k) = map(int, input().split())
	data = sorted([int(x) for x in input().split() if x != '0'])
	if len(data) == 0:
		print(0)
	elif len(data) == 1:
		print(1)
	else:
		for i in range(-2, max(-k - 2, -len(data) - 1), -1):
			data[-1] += data[i]
			data[i] = 0
		print(data[-1])


class Solution:

	def __init__(self, n, k, list_a):
		self.n = n
		self.k = k
		self.list_a = list_a

	def solve(self):
		if self.k == n - 1:
			return sum(self.list_a)
		self.list_a.sort(reverse=True)
		return sum(self.list_a[:self.k + 1])
t = int(input())
for _ in range(t):
	(n, k) = map(lambda x: int(x), list(input().split(' ')))
	list_a = list(map(lambda x: int(x), list(input().split(' '))))
	s = Solution(n, k, list_a)
	print(s.solve())


t = int(input())
for i in range(t):
	l = input()
	L = l.split()
	for i in range(len(L)):
		L[i] = int(L[i])
	n = L[0]
	k = L[1]
	l = input()
	L = l.split()
	for i in range(len(L)):
		L[i] = int(L[i])
	L = sorted(L)
	s = 0
	if k >= n:
		k = n - 1
	for j in range(k + 1):
		s += L[n - j - 1]
	print(s)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	v = list(map(int, input().split()))
	v.sort(reverse=True)
	maximo = 0
	for i in range(k + 1):
		maximo += v[i]
	print(maximo)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	i = n - 2
	while k and i >= 0:
		if arr[i] == 0:
			break
		arr[-1] += arr[i]
		arr[i] = 0
		i -= 1
		k -= 1
	print(max(arr) - min(arr))


from functools import cmp_to_key
from collections import deque, Counter
from heapq import heappush, heappop
from math import log, ceil
import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def ii():
	return int(inp())

def si():
	return str(inp())

def li(lag=0):
	l = list(map(int, inp().split()))
	if lag != 0:
		for i in range(len(l)):
			l[i] += lag
	return l

def mi(lag=0):
	matrix = list()
	for i in range(n):
		matrix.append(li(lag))
	return matrix

def lsi():
	return list(map(str, inp().split()))

def print_list(lista, space=' '):
	print(space.join(map(str, lista)))

def bisect_left(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] < x:
			left = mid + 1
		else:
			right = mid
	return left

def bisect_right(a, x):
	left = 0
	right = len(a)
	while left < right:
		mid = (left + right) // 2
		if a[mid] > x:
			right = mid
		else:
			left = mid + 1
	return left

def bisect_elements(a, x):
	return bisect_right(a, x) - bisect_left(a, x)
MOD = 10 ** 9 + 7
maxN = 5
FACT = [0] * maxN
INV_FACT = [0] * maxN

def add(x, y):
	return (x + y) % MOD

def multiply(x, y):
	return x * y % MOD

def power(x, y):
	if y == 0:
		return 1
	elif y % 2:
		return multiply(x, power(x, y - 1))
	else:
		a = power(x, y // 2)
		return multiply(a, a)

def inverse(x):
	return power(x, MOD - 2)

def divide(x, y):
	return multiply(x, inverse(y))

def allFactorials():
	FACT[0] = 1
	for i in range(1, maxN):
		FACT[i] = multiply(i, FACT[i - 1])

def inverseFactorials():
	n = len(INV_FACT)
	INV_FACT[n - 1] = inverse(FACT[n - 1])
	for i in range(n - 2, -1, -1):
		INV_FACT[i] = multiply(INV_FACT[i + 1], i + 1)

def coeffBinom(n, k):
	if n < k:
		return 0
	return multiply(FACT[n], multiply(INV_FACT[k], INV_FACT[n - k]))

def create_graph(n, m, undirected=1, unweighted=1):
	graph = [[] for i in range(n)]
	if unweighted:
		for i in range(m):
			[x, y] = li(lag=-1)
			graph[x].append(y)
			if undirected:
				graph[y].append(x)
	else:
		for i in range(m):
			[x, y, w] = li(lag=-1)
			w += 1
			graph[x].append([y, w])
			if undirected:
				graph[y].append([x, w])
	return graph

def create_tree(n, unweighted=1):
	children = [[] for i in range(n)]
	if unweighted:
		for i in range(n - 1):
			[x, y] = li(lag=-1)
			children[x].append(y)
			children[y].append(x)
	else:
		for i in range(n - 1):
			[x, y, w] = li(lag=-1)
			w += 1
			children[x].append([y, w])
			children[y].append([x, w])
	return children

def dist(tree, n, A, B=-1):
	s = [[A, 0]]
	(massimo, massimo_nodo) = (0, 0)
	distanza = -1
	v = [-1] * n
	while s:
		(el, dis) = s.pop()
		if dis > massimo:
			massimo = dis
			massimo_nodo = el
		if el == B:
			distanza = dis
		for child in tree[el]:
			if v[child] == -1:
				v[child] = 1
				s.append([child, dis + 1])
	return (massimo, massimo_nodo, distanza)

def diameter(tree):
	(_, foglia, _) = dist(tree, n, 0)
	(diam, _, _) = dist(tree, n, foglia)
	return diam

def dfs(graph, n, A):
	v = [-1] * n
	s = [[A, 0]]
	v[A] = 0
	while s:
		(el, dis) = s.pop()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def bfs(graph, n, A):
	v = [-1] * n
	s = deque()
	s.append([A, 0])
	v[A] = 0
	while s:
		(el, dis) = s.popleft()
		for child in graph[el]:
			if v[child] == -1:
				v[child] = dis + 1
				s.append([child, dis + 1])
	return v

def parents_children_root_unrooted_tree(tree, n, root=0):
	q = deque()
	visited = [0] * n
	parent = [-1] * n
	children = [[] for i in range(n)]
	q.append(root)
	while q:
		all_done = 1
		visited[q[0]] = 1
		for child in tree[q[0]]:
			if not visited[child]:
				all_done = 0
				q.appendleft(child)
		if all_done:
			for child in tree[q[0]]:
				if parent[child] == -1:
					parent[q[0]] = child
					children[child].append(q[0])
			q.popleft()
	return (parent, children)

def all_longest_path_passing_from_node(parent, children, n):
	q = deque()
	visited = [len(children[i]) for i in range(n)]
	downwards = [[0, 0] for i in range(n)]
	upward = [1] * n
	longest_path = [1] * n
	for i in range(n):
		if not visited[i]:
			q.append(i)
			downwards[i] = [1, 0]
	while q:
		node = q.popleft()
		if parent[node] != -1:
			visited[parent[node]] -= 1
			if not visited[parent[node]]:
				q.append(parent[node])
		else:
			root = node
		for child in children[node]:
			downwards[node] = sorted([downwards[node][0], downwards[node][1], downwards[child][0] + 1], reverse=True)[0:2]
	s = [node]
	while s:
		node = s.pop()
		if parent[node] != -1:
			if downwards[parent[node]][0] == downwards[node][0] + 1:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][1])
			else:
				upward[node] = 1 + max(upward[parent[node]], downwards[parent[node]][0])
		longest_path[node] = downwards[node][0] + downwards[node][1] + upward[node] - min([downwards[node][0], downwards[node][1], upward[node]]) - 1
		for child in children[node]:
			s.append(child)
	return longest_path
for test in range(ii()):
	[n, k] = li()
	a = li()
	a = sorted(a)
	ma = 0
	i = 0
	while i < n and i <= k:
		ma += a[n - 1 - i]
		i += 1
	print(ma)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(j) for j in input().split()[:n]]
	a.sort(reverse=True)
	l = 0
	r = l + 1
	x = 0
	while r < k + 1:
		a[l] = a[l] + a[r]
		a[r] = 0
		x = a[l] - a[r]
		r += 1
	print(x)


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
inf = 1e+18
div = 998244353
for _ in range(inn()):
	(n, k) = value()
	a = arr()
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if a.count(0) == n:
		print(0)
	else:
		a.sort(reverse=True)
		m = a.pop(0)
		for i in range(k):
			m += a[i]
		print(m)


t = int(input())
while t > 0:
	t -= 1
	(n, k) = map(int, input().split())
	lst = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		lst.sort()
		print(sum(lst[n - k - 1:]))


t = int(input().strip())
for _ in range(t):
	(n, k) = (int(i.strip()) for i in input().split())
	a = [int(i.strip()) for i in input().split()]
	ordered = sorted(a)[-k - 1:]
	print(sum(ordered))


t = int(input())
for i in range(0, t):
	nk = input().split()
	n = int(nk[0])
	k = int(nk[1])
	M = list(map(int, input().split()))
	M.sort()
	M.reverse()
	s = 0
	for i in range(0, k + 1):
		s += M[i]
	print(s)


import sys, io, os
BUFSIZE = 8192

class FastIO(io.IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = io.BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(io.IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
T = int(input())
for _ in range(T):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=True)
	ans = sum(A[:K + 1])
	print(ans)


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	mas = list(map(int, input().split()))
	mas.sort()
	for i in range(n - 2, -1, -1):
		if k != 0:
			mas[n - 1] += mas[i]
			k -= 1
	print(mas[n - 1])


for ttt in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	summ = arr[0]
	for i in range(1, k + 1):
		summ += arr[i]
	print(summ)


t = int(input())
b = []
for i in range(t):
	(n, k) = map(int, input().split(' '))
	a = list(map(int, input().split(' ')))
	a.sort()
	a.reverse()
	p = sum(a[:k + 1])
	b.append(p)
for i in range(len(b)):
	print(b[i])


def find(A, k):
	a_s = sorted(A, reverse=True)
	if len(a_s) > 0:
		m = a_s[0]
		for i in range(1, k + 1):
			m += a_s[i]
		return m
	else:
		return 0

def main():
	T = int(input())
	for t in range(T):
		(n, k) = map(int, input().split())
		a = list(map(int, input().split()))
		print(find(a, k))
main()


import sys
import math, bisect
sys.setrecursionlimit(10 ** 6)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict

def I():
	return int(sys.stdin.readline())

def neo():
	return map(int, sys.stdin.readline().split())

def Neo():
	return list(map(int, sys.stdin.readline().split()))
for _ in range(I()):
	(n, k) = neo()
	A = Neo()
	A.sort(reverse=True)
	k = min(n - 1, k)
	i = 1
	Ans = A[0]
	while k:
		Ans += A[i]
		A[i] = 0
		i += 1
		k -= 1
	print(Ans - min(A))


t = int(input())

def find_max(a, k):
	if k == 0:
		return a[0] - a[-1]
	return sum(a[0:k + 1])
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	a = sorted(list(map(int, input().split())), reverse=True)
	print(find_max(a, k))


t = int(input())
while t > 0:
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	l.sort()
	while k > 0:
		l[n - 1] += l[n - k - 1]
		k -= 1
	print(l[n - 1])
	t -= 1


t = int(input())
for i in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	a = input().split()
	a = list(map(int, a))
	if sum(a) == 0 or len(a) == 1:
		print(sum(a))
		continue
	a.sort()
	for j in range(2, k + 2):
		if j - 1 >= len(a):
			break
		if a[-j] == 0:
			break
		a[-1] += a[-j]
		a[-j] = 0
	print(max(a) - min(a))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	ix = n - 2
	while k > 0:
		a[n - 1] = a[n - 1] + a[ix]
		a[ix] = 0
		ix = ix - 1
		k -= 1
	print(a[-1] - min(a))


for i in range(int(input())):
	(n, k) = map(int, input().split())
	li = list(map(int, input().split()))
	li.sort()
	li.reverse()
	s = sum(li[:k + 1])
	print(s)


t = int(input())

def solve():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	m = arr[n - 1]
	for i in range(k):
		m += arr[n - 2 - i]
	print(m)
for i in range(t):
	solve()


def maxdiff(n, k, arr):
	arr.sort()
	i = n - 2
	if n == 1:
		return 0
	while i > -1 and k > 0:
		arr[-1] += arr[i]
		i -= 1
		k -= 1
	if i == n - 2:
		return arr[-1] - arr[0]
	return arr[-1]
t = int(input())
for i in range(t):
	(n, k) = input().split()
	arr = list(map(int, input().split()))
	print(maxdiff(int(n), int(k), arr))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	b = sorted(a, reverse=True)
	summ = b[0]
	j = 1
	for i in range(k):
		a[j] = 0
		summ += b[j]
		j += 1
	print(summ - min(a))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	j = 0
	if a[n - 1] == 0:
		j = 0
	else:
		i = 0
		while i < k:
			a[n - 1] = a[n - 1] + a[n - i - 2]
			i += 1
			j = 1
	if j == 0:
		print(0)
	else:
		print(a[n - 1])


for i in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(num) for num in input().split()]
	l.sort()
	m = 0
	for j in range(n - 1, n - 2 - k, -1):
		m = m + l[j]
	if k > 0:
		print(m)
	else:
		print(m - l[0])


def pour_water(arr):
	return arr.pop(max(arr))
t = int(input())
for _ in range(t):
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	arr = list(map(int, input().split()))
	arr.sort()
	n = 0
	for _ in range(k + 1):
		n += arr.pop(-1)
	print(n)


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	barrels = []
	barrels.extend(list(map(int, input().split())))
	barrels.sort()
	ans = sum(barrels[n - k - 1:n])
	print(ans)


def solve(N, K, A):
	A.sort()
	END = N - 1
	if A[END] == 0:
		return 0
	i = END - 1
	for _ in range(K):
		if i < 0:
			break
		if A[i] == 0:
			break
		A[END] += A[i]
		A[i] = 0
		i -= 1
	return A[END]
T = int(input())
for _ in range(T):
	(N, K) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	answer = solve(N, K, A)
	print(answer)


import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7

def lcm(x, y):
	return x * y / gcd(x, y)

def fact(x, mod=mod):
	ans = 1
	for i in range(1, x + 1):
		ans = ans * i % mod
	return ans

def arr2D(n, m, default=0):
	lst = []
	for i in range(n):
		temp = [default] * m
		lst.append(temp)
	return lst

def sortDictV(x):
	return {k: v for (k, v) in sorted(x.items(), key=lambda item: item[1])}

def solve(n, k, lst):
	k = min(k, n)
	lst = sorted(lst, reverse=True)
	return sum(lst[:k + 1])
for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	print(solve(n, k, lst))


t = int(input())
for tt in range(0, t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	S = sum([a[x] for x in range(n - k - 1, n)])
	print(S)


import sys
r = sys.stdin.readline
for _ in range(int(r())):
	(n, k) = map(int, r().split())
	a = list(map(int, r().split()))
	a.sort()
	print(sum(a[-(k + 1):]))


t = int(input())
for l in range(t):
	(n, k) = [int(i) for i in input().split()]
	lis = [int(k) for k in input().split()]
	if n == 1:
		print(lis[0])
		continue
	lis.sort()
	if n == 2:
		print(lis[1] + lis[0])
		continue
	rp = n - 2
	maxi = 0
	for i in range(k):
		lis[n - 1] += lis[rp]
		rp -= 1
	print(lis[n - 1])


testcases = int(input())
for testcase in range(testcases):
	temparr = input()
	temparr = temparr.split()
	n = int(temparr[0])
	k = int(temparr[1])
	arr = []
	temparr = input()
	temparr = temparr.split()
	for i in temparr:
		arr.append(int(i))
	arr = sorted(arr)
	revarr = arr[::-1]
	if k >= n:
		ans = sum(arr)
		print(ans)
		continue
	curmax = revarr[0]
	if k == 0:
		print(max(arr) - min(arr))
		continue
	for i in range(k):
		curmax += revarr[i + 1]
		revarr[i] = 0
	print(curmax - min(revarr))


t = int(input())
while t:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a, reverse=True)
	s = 0
	for x in range(k + 1):
		s += a[x]
	print(s)
	t -= 1


from sys import stdin, stdout
cases = int(stdin.readline())
for i in range(cases):
	(a, b) = map(int, stdin.readline().split())
	lst = [int(i) for i in stdin.readline().split()]
	lst.sort()
	stdout.write(str(sum(lst[a - b - 1:])) + '\n')


t = int(input())
for _ in range(t):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	if k == 0:
		print(max(a) - min(a))
	elif k >= n - 1:
		s = sum(a)
		print(s)
	else:
		a.sort()
		s = 0
		for i in range(k + 1):
			s += a[-1 - i]
		print(s)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	array = sorted(map(int, input().split()))
	print(sum(array[-1 - k:]))


def solution():
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	minAmount = 0
	total = 0
	for i in range(n - k - 1, n):
		total += a[i]
	print(total - minAmount)
T = int(input())
while T:
	solution()
	T -= 1


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 998244353
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')

def solve():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		s = max(a)
		a.sort(reverse=True)
		for i in range(1, min(k + 1, n)):
			s += a[i]
		print(s)
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	input = sys.stdin.readline
solve()


t = int(input())
for i in range(t):
	ch1 = input()
	(n, k) = (int(ch1.split()[0]), int(ch1.split()[1]))
	ch2 = input()
	F = ch2.split()
	L = [int(F[i]) for i in range(n)]
	L = sorted(L)
	print(sum(L[n - 1 - k:n - 1]) + L[-1])


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = input().split()
	test = []
	for i in range(len(l)):
		test.append(int(l[i]))
	test.sort()
	som = sum(test[n - k - 1:])
	print(som)


ans = []
t = int(input())
while t != 0:
	(size, per) = input().split()
	size = int(size)
	per = int(per)
	ans = input().split()
	for i in range(0, size):
		ans[i] = int(ans[i])
	ans = sorted(ans)
	i = size - 2
	while per != 0 and ans[i] != 0 and (i >= 0):
		ans[size - 1] += ans[i]
		ans[i] = 0
		per -= 1
		i -= 1
	print(ans[size - 1])
	t -= 1


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	maxm = arr[-1]
	for i in range(1, 1 + k):
		maxm += arr[-1 - i]
	print(maxm)


t = int(input())
for _ in range(t):
	n = 0
	a = [int(s) for s in input().split()]
	b = [int(s) for s in input().split()]
	b.sort()
	for u in range(1, a[1] + 2):
		n += b[a[0] - u]
	print(n)


from math import *
sInt = lambda : int(input())
mInt = lambda : map(int, input().split())
lInt = lambda : list(map(int, input().split()))
t = sInt()
for _ in range(t):
	(n, k) = mInt()
	a = lInt()
	a.sort()
	m = sum(a[n - k - 1:n])
	print(m)


from collections import deque, defaultdict
from heapq import heapify, heappop
n = int(input())
for _ in range(n):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	maxheap = [-x for x in ar]
	heapify(maxheap)
	ma = -heappop(maxheap)
	for _ in range(k):
		if not maxheap:
			break
		ma += -heappop(maxheap)
	print(ma)


def che(arr, n, k):
	if sum(arr) == 0:
		return '0'
	else:
		res = 0
		arr.sort(reverse=True)
		for i in range(k + 1):
			res += arr[i]
		return res
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(che(arr, n, k))


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
t = ini()
for _ in range(t):
	(n, k) = inm()
	a = sorted(inl())
	print(sum(a[-k - 1:]))


def barrels(arr, k):
	return sum(sorted(arr, reverse=True)[:k + 1])
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(barrels(arr, k))


def count(mas, k):
	mas.sort(reverse=True)
	i = 1
	while k > 0 and i < len(mas):
		mas[0] += mas[i]
		k -= 1
		i += 1
	if i != 1 and len(mas) > 1:
		return mas[0]
	else:
		return 0
for i in range(int(input())):
	(n, k) = map(int, input().split())
	mas = list(map(int, input().split()))
	print(count(mas, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	lis.sort()
	ans = lis[-1]
	if n == 1:
		print(lis[0])
	i = n - 2
	while k > 0 and i >= 0:
		ans += lis[i]
		i -= 1
		k -= 1
	print(ans)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort(reverse=True)
	for i in range(1, k + 1):
		b[0] += b[i]
	print(b[0])


for i in range(int(input())):
	(n, k) = input().split()
	k = int(k)
	l = [int(j) for j in input().split()]
	l = sorted(l)
	while k != 0:
		l[-1] = l[-1] + l[-2]
		l[-2] = 0
		k -= 1
		l.pop(-2)
	print(l[-1])


def find_max_diff(xs, k):
	xs = sorted(xs, key=lambda x: -x)
	return sum(xs[0:k + 1])
n = int(input())
for t in range(n):
	(m, k) = map(int, input().split(' '))
	xs = map(int, input().split(' '))
	result = find_max_diff(xs, k)
	print(result)


import sys
import bisect as bi
import collections as cc
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, k) = I()
	l = I()
	l.sort()
	k += 1
	temp = l[-k:]
	print(sum(temp))


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
for _ in range(val()):
	(n, k) = li()
	l = sorted(li())
	for i in range(k):
		l[-1] += l[n - i - 2]
	print(l[-1])


from sys import stdin, stdout
t = int(input())
while t > 0:
	t = t - 1
	arr = []
	a = []
	arr = [int(x) for x in stdin.readline().split()]
	n = arr[0]
	k = arr[1]
	a = [int(x) for x in stdin.readline().split()]
	a.sort(reverse=True)
	sum = 0
	for i in range(0, k + 1):
		sum += a[i]
	print(sum)


import os
import sys
from io import BytesIO, IOBase
_str = str
str = lambda x=b'': x if type(x) is bytes else _str(x).encode()
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def input():
	return sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())))
	mn = 0 if k else l[0]
	for i in range(n - 2, -1, -1):
		if not k:
			break
		l[-1] += l[i]
		k -= 1
	print(l[-1] - mn)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	lst1 = map(int, input().split())
	lst = list(lst1)
	x = lst.count(0)
	ans = 0
	lst.sort()
	if k > n - x:
		k = n - x
	for i in range(1, k + 2):
		ans += lst[n - i]
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	barrels = list(map(int, input().split()))
	barrels.sort()
	large = barrels[n - 1]
	idx = n - 2
	while k > 0:
		large += barrels[idx]
		idx -= 1
		k -= 1
	print(large)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=300006, func=lambda a, b: min(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] > k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater

class TrieNode:

	def __init__(self):
		self.children = [None] * 26
		self.isEndOfWord = False

class Trie:

	def __init__(self):
		self.root = self.getNode()

	def getNode(self):
		return TrieNode()

	def _charToIndex(self, ch):
		return ord(ch) - ord('a')

	def insert(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				pCrawl.children[index] = self.getNode()
			pCrawl = pCrawl.children[index]
		pCrawl.isEndOfWord = True

	def search(self, key):
		pCrawl = self.root
		length = len(key)
		for level in range(length):
			index = self._charToIndex(key[level])
			if not pCrawl.children[index]:
				return False
			pCrawl = pCrawl.children[index]
		return pCrawl != None and pCrawl.isEndOfWord

class Node:

	def __init__(self, data):
		self.data = data
		self.count = 0
		self.left = None
		self.right = None

class BinaryTrie:

	def __init__(self):
		self.root = Node(0)

	def insert(self, pre_xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = pre_xor & 1 << i
			if val:
				if not self.temp.right:
					self.temp.right = Node(0)
				self.temp = self.temp.right
				self.temp.count += 1
			if not val:
				if not self.temp.left:
					self.temp.left = Node(0)
				self.temp = self.temp.left
				self.temp.count += 1
		self.temp.data = pre_xor

	def query(self, xor):
		self.temp = self.root
		for i in range(31, -1, -1):
			val = xor & 1 << i
			if not val:
				if self.temp.left and self.temp.left.count > 0:
					self.temp = self.temp.left
				elif self.temp.right:
					self.temp = self.temp.right
			elif self.temp.right and self.temp.right.count > 0:
				self.temp = self.temp.right
			elif self.temp.left:
				self.temp = self.temp.left
			self.temp.count -= 1
		return xor ^ self.temp.data
for ik in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	for i in range(k):
		l[n - 1] += l[n - 2 - i]
		l[n - 2 - i] = 0
	print(l[n - 1])


T = int(input())
ans = []
for s in range(T):
	(x, y) = input().split()
	x = int(x)
	y = int(y) + 1
	t = list(map(int, input().split()[:x]))
	t.sort(reverse=True)
	diff = sum(t[:y])
	ans.append(diff)
print(*ans, sep='\n')


from sys import stdout, stdin
from collections import defaultdict, deque
import math
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	l = list(map(int, stdin.readline().split()))
	l.sort(reverse=True)
	ans = 0
	for i in range(k + 1):
		ans += l[i]
	print(ans)


for i in range(int(input())):
	(n, k) = map(int, input().split(' '))
	nums = list(map(int, input().split(' ')))
	nums.sort(reverse=True)
	sum1 = nums[0] + sum(nums[1:k + 1])
	print(sum1)


tc = int(input())
for _ in range(tc):
	inp = [int(i) for i in str(input()).split(' ')]
	barrels = inp[0]
	k = inp[1]
	if k >= barrels:
		k = barrels - 1
	barrelList = [int(i) for i in str(input()).split(' ')]
	barrelList.sort()
	print(sum(barrelList[-1:-1 - k - 1:-1]))


n = int(input())
for i in range(n):
	(m, l) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a = sorted(a, reverse=True)
	e = 0
	for j in range(0, len(a) - 1):
		e = e + 1
		a[j + 1] = a[j] + a[j + 1]
		a[j] = 0
		if e == l:
			break
	print(max(a) - min(a))


t = int(input())
for h in range(t):
	(a, b) = map(int, input().split())
	asd = []
	for i in map(int, input().split()):
		asd.append(i)
	asd.sort(reverse=True)
	result = 0
	for i in range(b + 1):
		result += asd[i]
	print(result)


def kek():
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	for i in range(1, k + 1):
		t = arr[i]
		arr[0] += t
		arr[i] -= t
	print(arr[0] - min(arr))
t = int(input())
for i in range(t):
	kek()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	maxx = arr[-1]
	for i in range(n - 2, -1, -1):
		if k:
			maxx += arr[i]
			k -= 1
		else:
			break
	print(maxx)


from sys import stdin
import collections, heapq, functools

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def solve(A, k):
	A = [-i for i in A]
	heapq.heapify(A)
	ans = -1 * heapq.heappop(A)
	while k > 0:
		v = heapq.heappop(A)
		ans += -1 * v
		k -= 1
	return ans
t = int(input())
for _ in range(t):
	(barrels, k) = ip()
	A = ip()
	print(solve(A, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	list1 = [int(x) for x in input().split()]
	list1.sort()
	list1.reverse()
	totalSum = list1[0]
	for i in range(1, k + 1):
		totalSum += list1[i]
	print(totalSum)


import sys, math
input = lambda : sys.stdin.readline().rstrip()
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)[::-1]
	ans = a[0]
	del a[0]
	n -= 1
	for i in range(min(n, k)):
		ans += a[i]
	print(ans)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = [int(j) for j in input().split()]
	a.sort()
	print(sum(a[n - (k + 1):]))


def solution(arr, k):
	arr.sort(reverse=True)
	for i in range(min(len(arr) - 1, k)):
		arr[i + 1] = arr[i] + arr[i + 1]
	return max(arr)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	print(solution(arr, k))


for i1 in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	temp = l[:k + 1]
	ans = sum(temp)
	print(ans)


for _ in range(int(input())):
	(N, K) = [int(i) for i in input().split(' ')]
	A = [int(i) for i in input().split(' ')]
	A.sort()
	A = A[::-1]
	sum = 0
	for i in range(0, K + 1):
		sum += A[i]
	print(sum)


t = int(input())
for i in range(0, t):
	n_k = list(map(int, input().split()))
	b = list(map(int, input().split()))
	n = n_k[0]
	k = n_k[1]
	b = sorted(b)
	count = b[-1]
	c = -1
	for i in range(0, k):
		c = c - 1
		count = count + b[c]
		b[c] = 0
	if k == len(b) - 1:
		print(f'{count}')
	else:
		d = count - min(b)
		print(f'{d}')


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	sum_a = 0
	if sum(array) == 0:
		print(0)
		break
	array.sort()
	array = array[::-1]
	print(sum(array[:k + 1]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	ll = sorted(list(map(int, input().split())))
	if sum(ll) == 0 or len(ll) == 1:
		print(0)
	else:
		for i in range(n - 2, -1, -1):
			if k == 0:
				break
			ll[-1] += ll[i]
			k -= 1
		print(ll[-1])


t = int(input())
while t > 0:
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if k == 0:
		print(max(a) - min(a))
	a.sort()
	ans = a[-1]
	i = len(a) - 2
	while k > 0:
		ans = ans + a[i]
		i -= 1
		k -= 1
	print(ans)
	t -= 1


import os
import heapq
import sys, threading
import math
import operator
from collections import defaultdict, deque
from io import BytesIO, IOBase
sys.setrecursionlimit(10 ** 5)

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def pw(a, b, md):
	result = 1
	while b > 0:
		if b % 2 == 1:
			result *= a
			result %= md
		a *= a
		a %= md
		b //= 2
	return result % md

def inpt():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, k) = inpt()
		ar = inpt()
		ar.sort(reverse=True)
		for i in range(1, n):
			if k == 0:
				break
			ar[0] += ar[i]
			ar[i] = 0
			k -= 1
		print(max(ar) - min(ar))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
threading.Thread(target=main).start()


t = int(input())
for ti in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	ans = a[0]
	for i in range(1, k + 1):
		ans += a[i]
		a[i] = 0
	print(ans - a[1])


import sys

def findmax(klist):
	a = klist[0]
	g = 0
	for i in range(0, len(klist)):
		if klist[i] > a:
			a = klist[i]
			g = i
	return [a, g]

def findmin(klist):
	a = klist[0]
	g = 0
	for i in range(0, len(klist)):
		if klist[i] < a:
			a = klist[i]
			g = i
	return [a, g]
testamt = int(sys.stdin.readline())
for i in range(0, testamt):
	k = int(sys.stdin.readline().split()[1])
	fill = sys.stdin.readline().split()
	for i in range(0, len(fill)):
		fill[i] = int(fill[i])
	fill.sort(reverse=True)
	maxfill = 0
	out = 0
	for i in range(0, k + 1):
		maxfill += fill[i]
	if k == 0:
		out = fill[0]
	sys.stdout.write(str(maxfill - out))
	sys.stdout.write('\n')


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	z = list(map(int, input().split()))
	z = sorted(z)
	s = max(z)
	z.pop()
	z = z[::-1]
	for i in z:
		if k == 0:
			break
		else:
			s = s + i
			k = k - 1
	print(s)


def program():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	c = 0
	arr.sort()
	for i in range(n - 2, -1, -1):
		arr[-1] += arr[i]
		arr[i] = 0
		c += 1
		if c == k:
			break
	print(arr[-1] - arr[-2])
for i in range(int(input())):
	program()


from math import *
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = sorted(list(map(int, input().split())), reverse=True)
	i = 1
	while k > 0 and i < len(l):
		l[0] += l[i]
		l[i] = 0
		i += 1
		k -= 1
	l = sorted(l, reverse=True)
	print(l[0] - l[len(l) - 1])


t = int(input())
for i in range(t):
	(n, k) = [int(x) for x in input().split()]
	l = [int(x) for x in input().split()]
	l.sort()
	i = len(l) - 1
	c = 0
	s = 0
	while c <= k:
		s += l[i]
		i -= 1
		c += 1
	print(s)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = input()
	s = list(map(int, l.split()))
	s.sort()
	d = 0
	for j in range(k + 1):
		c = s[n - 1 - j]
		d = d + c
	print(d)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	(maximum, minimum) = (arr[0], arr[0])
	arr.sort()
	if k > n - 1:
		k = n - 1
	h = 0
	while k > h:
		arr[n - 1] += arr[n - 2 - h]
		arr[n - 2 - h] = 0
		h += 1
	print(arr[n - 1])


from sys import stdin
_input = stdin.readline
(_max, _dict, _sorted, _int, _range, _min) = (max, dict, sorted, int, range, min)
from collections import defaultdict

def solution():
	for _ in _range(_int(_input())):
		(n, k) = [_int(i) for i in _input().split()]
		c = defaultdict(_int)
		for i in _input().split():
			c[_int(i)] += 1
		max_key = _max(c.keys())
		min_key = _min(c.keys())
		if k == 0:
			print(max_key - min_key)
			continue
		else:
			ans = max_key
			c[max_key] -= 1
			for i in _sorted(c.keys(), reverse=True):
				if c[i] >= k:
					ans += i * k
					k = 0
				else:
					ans += i * c[i]
					k -= c[i]
			print(ans)
solution()


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	if k == 0:
		print(max(a) - min(a))
		return
	else:
		s = sum(a[:k + 1])
		print(s)
		return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	maxs = arr[-1]
	for i in range(k):
		maxs += arr[-2 - i]
	print(maxs)


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	j = n - 2
	if k >= n - 1:
		print(sum(a))
	else:
		for i in range(0, k):
			a[n - 1] += a[j]
			a[j] = 0
			j = j - 1
		print(max(a) - min(a))


def do():
	q = int(input())
	for _ in range(q):
		(n, k) = map(int, input().split())
		dat = list(map(int, input().split()))
		dat.sort(reverse=True)
		print(sum(dat[:k + 1]))
do()


l = []
t = int(input())
for i in range(t):
	l = [int(x) for x in input().split()]
	if len(l) == 2:
		n = l[0]
		k = l[1]
		a = [int(x) for x in input().split()]
		if len(a) == n:
			a.sort()
			max = a[-1]
			for i in range(1, k + 1):
				max = max + a[-1 - i]
			print(max)


n = int(input())
for i in range(n):
	(j, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	arr.sort()
	arr.reverse()
	b = 1
	while k:
		arr[0] = arr[0] + arr[b]
		arr[b] = 0
		b += 1
		k -= 1
	mx = arr[0]
	mn = min(arr)
	print(mx - mn)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	i = n - 2
	while k and i > -1:
		a[-1] += a[i]
		a[i] = 0
		i -= 1
		k -= 1
	print(a[-1])


for _ in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	min_a = a[0]
	max_a = a[-1]
	for i in reversed(range(0, n - 1)):
		if k == 0:
			break
		k -= 1
		max_a += a[i]
		min_a = 0
	print(max_a - min_a)


import sys
a = int(sys.stdin.readline())
for x in range(a):
	(b, c) = map(int, sys.stdin.readline().split())
	l = list(map(int, sys.stdin.readline().split()))
	l.sort()
	s = l[b - 1]
	for g in range(b - 2, b - 2 - c, -1):
		s += l[g]
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	max_amount = a[n - 1]
	i = n - 2
	for _ in range(k):
		max_amount = max_amount + a[i]
		i = i - 1
	print(max_amount)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	i = -2
	j = -1
	if k > n:
		print(sum(arr))
	elif k > 0:
		arr.insert(0, 0)
		res = sum(arr[-k - 1:])
		print(res - min(arr))
	elif k == 0:
		print(max(arr) - min(arr))


def solve(arr, n, k):
	if n <= k + 1:
		return sum(arr)
	if k == 0:
		return max(arr) - min(arr)
	arr.sort()
	i = n - 2
	while k > 0:
		arr[n - 1] += arr[i]
		k -= 1
		i -= 1
	return arr[n - 1]
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(arr, n, k))


t = int(input(''))
for i in range(t):
	(n, k) = map(int, input('').split())
	a = list(map(int, input('').split()))
	d = max(a)
	a.remove(d)
	a.sort(reverse=True)
	print(d + sum(a[0:k:1]))


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline
	for _ in range(int(input())):
		(N, K) = map(int, input().split())
		A = list(map(int, input().split()))
		A.sort(reverse=True)
		if K == 0:
			print(A[0] - A[-1])
		else:
			print(sum(A[:min(K + 1, len(A))]))
main()


import os
import sys
from io import BytesIO, IOBase
_str = str
BUFSIZE = 8192

def str(x=b''):
	return x if type(x) is bytes else _str(x).encode()

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def inp():
	return sys.stdin.readline()

def mpint():
	return map(int, sys.stdin.readline().split(' '))

def itg():
	return int(sys.stdin.readline())

def rindex(array, value):
	for i in range(len(array) - 1, -1, -1):
		if array[i] == value:
			return i
	raise ValueError('{} is not in list'.format(value))

def solve():
	(n, k) = mpint()
	arr = sorted(mpint(), reverse=True)
	return sum(arr[:k + 1])
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
for _ in range(itg()):
	print(solve())


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	ar = sorted(ar)
	ans = 0
	for i in range(k):
		ans += ar[n - i - 2]
	print(ans + ar[n - 1])


def arrin():
	return list(map(int, input().strip().split()))

def sorter(a):
	a.sort()
t = int(input())
for i in range(0, t):
	x = arrin()
	n = x[0]
	k = x[1]
	a = arrin()
	sorter(a)
	diff = a[n - 1]
	for j in range(1, k + 1):
		diff += a[n - 1 - j]
	print(diff)


rw = int(input())
for wewq in range(rw):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	f = 0
	for i in range(k + 1):
		f += a[i]
	print(f)


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	Max = 0
	for j in range(min(len(a), k + 1)):
		Max += a[j]
	print(Max)


def solve(barrels, k):
	barrels.sort()
	n = len(barrels)
	i = n - k - 1
	while i < n - 1:
		barrels[i + 1] += barrels[i]
		i += 1
	return barrels[n - 1]

def main(input_path=0):
	with open(input_path) as f:
		t = int(f.readline().strip())
		for _ in range(t):
			(n, k) = [int(x) for x in f.readline().strip().split(' ')]
			print(solve([int(x) for x in f.readline().strip().split(' ')], k))
main()


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
	elif k >= n - 1:
		print(sum(a))
	else:
		a.sort(reverse=True)
		print(sum(a[0:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = input().split()
	n = int(n)
	k = int(k)
	if k == 0:
		print(max(b) - min(b))
		continue
	b = list(map(int, input().split()))
	b.sort()
	j = n - 2
	s = b[n - 1]
	while k != 0:
		if b[j] == 0:
			break
		s += b[j]
		j -= 1
		k -= 1
	print(s)


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math
from collections import defaultdict
for _ in range(ri()):
	(n, k) = ria()
	l = ria()
	l.sort(reverse=1)
	cnt = l[0]
	for i in range(1, k + 1):
		cnt += l[i]
	wi(cnt)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	li = list(map(int, input().split()))
	li.sort()
	res = li[n - 1]
	for i in range(n - 2, -1, -1):
		if m:
			res += li[i]
			m -= 1
	print(res)


def factorial(n):
	if n == 1:
		return 0
	return n * fact(n - 1)
for j in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort(reverse=True)
	x = a[0]
	a = a[1:]
	for i in range(k):
		if a[i] == 0:
			break
		x += a[i]
		a[i] = 0
	print(x - min(a))


def main():
	(N, K) = list(map(int, input().split()))
	(*A,) = list(map(int, input().split()))
	A.sort()
	print(A[-1] + sum(A[-K - 1:-1]))

def __starting_point():
	for __ in [0] * int(input()):
		main()
__starting_point()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	am = sorted(arr)
	i = len(arr) - 2
	while k > 0 and i >= 0:
		am[-1] += am[i]
		i -= 1
		k -= 1
	print(am[-1])


from collections import defaultdict
test = int(input())
for i in range(test):
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	fre = defaultdict(int)
	se = []
	temp = 0
	for i in range(n):
		if a[i] not in fre:
			fre[a[i]] = 1
			se.append(a[i])
		else:
			fre[a[i]] += 1
	if k == 0:
		print(max(se) - min(se))
	else:
		se.sort(reverse=True)
		j = 0
		temp = max(se)
		fre[temp] -= 1
		for i in se:
			if k > 0:
				if fre[i] < k:
					k -= fre[i]
					temp += fre[i] * i
				else:
					temp += k * i
					k = 0
			else:
				break
	print(temp)


t = int(input())
for _ in range(t):
	(n, k) = list(map(int, input().split()))
	s = sorted(list(map(int, input().split())))
	ans = s[-1]
	i = n - 2
	while k > 0:
		ans = ans + s[i]
		i = i - 1
		k = k - 1
		if i == -1:
			break
	print(ans)


def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	rs = a[0]
	if k == 0:
		rs -= a[n - 1]
	for x in range(1, k + 1):
		rs += a[x]
	print(rs)
tests = int(input())
while tests != 0:
	solve()
	tests = tests - 1


from bisect import *
from collections import *
from random import *
from decimal import *
from itertools import *
import sys
input = sys.stdin.readline

def inp():
	return int(input())

def st():
	return input().rstrip('\n')

def lis():
	return list(map(int, input().split()))

def ma():
	return map(int, input().split())
t = inp()
while t:
	t -= 1
	(n, k) = ma()
	a = lis()
	a.sort()
	print(sum(a[n - k - 1:]))


from collections import Counter
import string
import math
import sys

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
for _ in range(vary(1)):
	(n, k) = vary(2)
	num = array_int()
	nt = num[:n - 1]
	nt.sort(reverse=True)
	ans = 0
	for i in range(k):
		ans += nt[i]
	if k >= n - 1:
		print(sum(num))
	else:
		ans += max(num[-1], nt[k])
		print(ans)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	a = [int(x) for x in input().split()]
	a = sorted(a, reverse=True)
	a[0] = sum(a[:k + 1])
	a[1:k + 1] = [0 for i in range(k)]
	a = sorted(a, reverse=True)
	print(abs(a[0] - a[-1]))


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted([*map(int, input().split())], reverse=True)
	c = a[1:]
	print(a[0] + sum(c) if len(c) <= k else sum(c[:k]) + a[0])


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	v = min(n - 1, k)
	count = 0
	for i in range(v + 1):
		count += a[i]
	print(count)


import math
t = int(input())
for w in range(t):
	(n, k) = (int(i) for i in input().split())
	l = sorted([int(i) for i in input().split()])
	for i in range(n - 2, n - 2 - k, -1):
		l[-1] += l[i]
	print(l[-1])


t = int(input())
while t:
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l.append(sum(l[-1:-k - 2:-1]))
	print(max(l))
	t -= 1


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import ceil, floor, sqrt, log2, gcd
from heapq import heappush, heappop
abc = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	arr.reverse()
	for i in range(k):
		arr[0] += arr[1 + i]
	print(arr[0])


import sys
lines = sys.stdin.readlines()

def barrels(barr, c):
	count = 0
	diffVal = 0
	barr = sorted(barr)
	while count < c:
		if count == 0:
			diffVal = barr[-(count + 1)] + barr[-(count + 2)]
		else:
			diffVal += barr[-(count + 2)]
		count += 1
	print(diffVal)
count = 0
c = 0
for line in lines[1:]:
	if count % 2 == 0:
		c = line.split()
		c = int(c[1])
	else:
		barrel = line.split()
		barrel = list(map(int, barrel))
		barrels(barrel, c)
	count += 1


cases = int(input())
for _ in range(cases):
	(n, k) = [int(i) for i in input().split()]
	nums = [int(i) for i in input().split()]
	nums.sort()
	start = max(n - k - 1, 0)
	for i in range(start, n - 1):
		nums[-1] += nums[i]
		nums[i] = 0
	print(nums[-1])


def floornum():
	t = int(input())
	for i in range(t):
		(n, k) = [int(x) for x in input().split()]
		a = list(map(int, input().split()))
		m = 1
		a.sort(reverse=True)
		ma = a[0]
		for i in range(k):
			ma += a[m]
			m += 1
		if k != 0:
			print(ma, end='\n')
		else:
			print(a[0] - a[-1], end='\n')
floornum()


for i in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	l = sorted([int(i) for i in input().split()])
	for i in range(k):
		l[-1] += l[-2 - i]
		l[-2 - i] = 0
	print(max(l) - min(l))


i = lambda : [*map(int, input().split())]
for _ in range(i()[0]):
	(n, k) = i()
	l = sorted(i())
	print(sum(l[:-k - 2:-1]))


for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	arr = [int(i) for i in input().split()]
	arr.sort()
	print(sum(arr[n - 1 - k:]))


n = int(input())
for i in range(0, n):
	o = input().rstrip().split(' ')
	p = input().rstrip().split(' ')
	k = int(o[1])
	p.sort(key=int)
	A = int(p[len(p) - 1])
	p.reverse()
	del p[0]
	for j in range(0, k):
		A += int(p[j])
	print(A)


t = int(input())
list1 = []
for i in range(t):
	b = 0
	(n, k) = map(int, input().split())
	t = [int(a) for a in input().split()]
	if k == 0:
		b = max(t) - min(t)
	elif k < n:
		t.sort(reverse=True)
		b = sum(t[:k + 1])
	else:
		b = sum(t)
	list1.append(b)
for i in list1:
	print(i)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	count = 0
	for i in range(k + 1):
		count += l[i]
	print(count)


for u in range(int(input())):
	(n, k) = map(int, input().split())
	x = [int(w) for w in input().split()]
	x = sorted(x)
	x = x[::-1]
	maxi = sum(x[:k + 1])
	print(maxi)


T = int(input())
for t in range(T):
	(n, k) = [int(_) for _ in input().split()]
	a = sorted((int(_) for _ in input().split()), reverse=True)
	print(sum(a[1:k + 1], a[0]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	nn = [int(s) for s in input().split()]
	nn.sort(reverse=True)
	r = nn[0]
	for i in range(1, k + 1):
		r += nn[i]
	print(r)


tt = int(input())
while tt:
	tt -= 1
	m = list(map(int, input().split()))
	ll = list(map(int, input().split()))
	n = m[0]
	k = m[1]
	l = sorted(ll, reverse=True)
	if max(l) == 0:
		print('0')
	else:
		for i in range(1, k + 1):
			l[0] += l[i]
			l[i] -= l[i]
		a = max(l)
		b = min(l)
		print(a - b)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	array = list(map(int, input().split()))
	array.sort()
	array.reverse()
	big = array[0]
	for i in range(1, k + 1):
		big += array[i]
	print(big)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)[::-1]
	barrel = a[0]
	for i in range(1, n):
		k -= 1
		barrel += a[i]
		if k == 0:
			break
	print(barrel)


import sys
input = lambda : sys.stdin.readline().rstrip()
from collections import deque
from queue import LifoQueue

def binary_search(a, n):
	L = 0
	R = len(a) - 1
	while L <= R:
		mid = L + (R - L) // 2
		if a[mid] == n:
			return mid
		elif a[mid] < n:
			L = mid + 1
		else:
			R = mid - 1
	return -1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	s = 0
	for i in range(min(k + 1, n)):
		s += a[-i - 1]
	print(s)


T = int(input())
while T > 0:
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	res = sum(arr[max(0, n - k - 1):])
	print(res)
	T -= 1


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'

def get_input(a=str):
	return a(input())

def get_int_input():
	return get_input(int)

def get_input_arr(a):
	return list(map(a, input().split()))

def get_int_input_arr():
	return get_input_arr(int)

def solve():
	t = get_int_input()
	for _ in range(t):
		(n, k) = get_int_input_arr()
		arr = get_int_input_arr()
		arr.sort()
		st_ptr = len(arr) - 2
		while k and st_ptr > -1:
			if arr[st_ptr] > 0:
				arr[-1] += arr[st_ptr]
				arr[st_ptr] = 0
				k -= 1
			else:
				st_ptr -= 1
		cout << arr[-1] - min(arr) << endl

def main():
	solve()
main()


import sys
input = sys.stdin.readline
spl = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, k) = spl()
	s = sorted(spl())
	print(sum(s[-(k + 1):]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = [int(i) for i in input().split()]
	l.sort(reverse=True)
	out = l[0]
	if n == 1:
		print(out)
		continue
	else:
		i = 1
		while i < n and k >= 1:
			out += l[i]
			i += 1
			k -= 1
		print(out)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(map(int, input().split()))
	print(sum(a[-k - 1:]))


from sys import stdin
from sys import stdout
import math
import io, os

def solve(n, k, arr):
	arr.sort()
	total = arr[-1]
	for i in range(k):
		total += arr[n - 2 - i]
	return total
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(n, k, arr))


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(x)
lcm = lambda x, y: x * y // gcd(x, y)
hg = lambda x, y: (y + x - 1) // x * x
pw = lambda x: 1 if x == 1 else 1 + pw(x // 2)
chk = lambda x: chk(x // 2) if not x % 2 else True if x == 1 else False
sm = lambda x: (x ** 2 + x) // 2
N = 10 ** 9 + 7
for _ in range(I()):
	(n, k) = R()
	a = sorted(R())
	print(a[-1] + sum(a[:-1][::-1][:min(n - 1, k)]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	s = 0
	for i in range(n - 2, -1, -1):
		l[-1] += l[i]
		l[i] = 0
		s += 1
		if s == k:
			break
	print(max(l) - min(l))


def solve():
	(n, k) = map(int, input().split())
	arr = [int(x) for x in input().split()]
	arr.sort()
	if n == 2:
		arr[1] += arr[0]
		arr[0] = 0
		print(arr[1] - arr[0])
		return
	l = n - 2
	while k > 0 & l >= 0:
		arr[-1] += arr[l]
		l -= 1
		k -= 1
	print(arr[-1])
	return

def main():
	t = int(input())
	for i in range(t):
		solve()
	return
main()


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split(' ')]
	a = sorted([int(i) for i in input().split(' ')])
	k = min(n, k)
	print(sum(a[len(a) - k - 1:]))


cycles = int(input())
for cycle in range(cycles):
	inp = input().split(' ')
	k = int(inp[1])
	n = int(inp[0])
	inp = [int(i) for i in input().split(' ')]
	inp = sorted(inp, reverse=True)
	sum = 0
	for i in inp:
		if k >= 0:
			k -= 1
		else:
			break
		sum += i
	print(sum)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	sm = a[-1]
	K = k
	for i in range(n - 2, -1, -1):
		if K > 0:
			K -= 1
			sm += a[i]
	print(sm)


t = int(input())
for i in range(t):
	(N, K) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort()
	print(sum(A[-K - 1:]))


Type = True

def solve(q):
	(n, k, il) = q
	il.sort()
	il.reverse()
	il = il[0:k + 1]
	ans = sum(il)
	return ans

def cin():
	(n, k) = [int(_) for _ in input().split()]
	il = input().split()
	for _ in range(n):
		il[_] = int(il[_])
	lis = [n, k, il]
	return lis

def main(Type):
	if Type == True:
		i = int(input())
	else:
		i = 1
	for tc in range(1, i + 1):
		inp = cin()
		ans = solve(inp)
		print(ans)
main(Type)


t = int(input())
for q in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	for i in range(n - 2, -1, -1):
		if k:
			l[n - 1] += l[i]
			k -= 1
			l[i] = 0
		else:
			break
	l.sort()
	print(l[n - 1] - l[0])


a = []
t = int(input())
for i in range(t):
	n1 = input().split()
	n = int(n1[0])
	k = int(n1[1])
	a = [int(i) for i in input().split()]
	a.sort(reverse=True)
	ca = 0
	for j in range(k + 1):
		ca += a[j]
	print(ca)


t = int(input())
for test in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	arr = arr[::-1]
	s = 0
	for i in range(k + 1):
		s += arr[i]
	print(s)


import os
import sys
from io import BytesIO, IOBase
import threading
from bisect import bisect_right
from math import gcd, log
from collections import Counter
from pprint import pprint

def main():
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	ans = arr[0]
	i = 1
	while i <= k and i < n:
		ans += arr[i]
		i += 1
	print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	main()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	(n, k) = map(int, sys.stdin.readline().split())
	A = list(map(int, sys.stdin.readline().split()))
	A.sort()
	print(sum(A[-k - 1:]))


import io
import os
import sys
import math
import heapq
input = sys.stdin.readline
mod = 10 ** 9 + 7
t = int(input())
for i in range(t):
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	if max(arr) == 0:
		print(0)
	elif k == 0:
		print(max(arr) - min(arr))
	else:
		ans = arr[0] + sum(arr[1:1 + k])
		print(ans)


from __future__ import division, print_function
import os, sys
import math
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def sli():
	return list(msi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def factorial(n):
	return 1 if n == 1 or n == 0 else n * factorial(n - 1)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, x):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] > x:
			return binary_search(arr, low, mid - 1, x)
		else:
			return binary_search(arr, mid + 1, high, x)
	else:
		return -1

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	print(decimal)

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def find_lcm(num1, num2):
	if num1 > num2:
		num = num1
		den = num2
	else:
		num = num2
		den = num1
	rem = num % den
	while rem != 0:
		num = den
		den = rem
		rem = num % den
	gcd = den
	lcm = int(int(num1 * num2) / int(gcd))
	return lcm

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def main():
	for _ in range(ii()):
		(n, k) = mi()
		a = li()
		a.sort(reverse=True)
		j = sum(a[0:k + 1])
		print(j)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	if n == k:
		print(sum(a))
		continue
	elif k == 0:
		print(max(a) - min(a))
	print(sum(a[::-1][:k + 1]))


cases = int(input())
while cases:
	cases -= 1
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = sorted(arr, reverse=True)
	if len(arr) == 2:
		print(sum(arr))
	else:
		mn = 0
		mx = arr.pop(0)
		for n in arr:
			if k > 0:
				mx += n
				k -= 1
		print(mx - mn)


from sys import *
from math import *
from bisect import *
t = int(stdin.readline())
for _ in range(t):
	(n, k) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	y = a.pop(-1)
	a = a[::-1]
	for i in range(len(a)):
		if k == 0:
			break
		y += a[i]
		k -= 1
	print(y)


tc = int(input())
for tcc in range(1, tc + 1):
	(b, ops) = map(int, input().split())
	barrels = list(map(int, input().split()))
	if ops == 0:
		print(max(barrels) - min(barrels))
	else:
		barrels.sort()
		barrels.reverse()
		tot = 0
		barrels = barrels[:ops + 1]
		print(sum(barrels))


T_ON = 1
DEBUG_ON = 0
MOD = 998244353

def solve():
	(n, k) = read_ints()
	A = read_ints()
	A.sort()
	print(sum(A[-k - 1:]))

def main():
	T = read_int() if T_ON else 1
	for i in range(T):
		solve()

def debug(*xargs):
	if DEBUG_ON:
		print(*xargs)
from collections import *
import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def read_int():
	return int(input())

def read_ints():
	return list(map(int, input().split()))

def print_nums(nums):
	print(' '.join(map(str, nums)))

def YES():
	print('YES')

def Yes():
	print('Yes')

def NO():
	print('NO')

def No():
	print('No')

def First():
	print('First')

def Second():
	print('Second')

def fib(n):
	(a, b) = (0, 1)
	for _ in range(n):
		(a, b) = (b, a + b)
	return a

def fib_ns(n):
	assert n >= 1
	f = [0 for _ in range(n + 1)]
	f[0] = 0
	f[1] = 1
	for i in range(2, n + 1):
		f[i] = f[i - 1] + f[i - 2]
	return f

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def xgcd(a, b):
	(x0, x1, y0, y1) = (0, 1, 1, 0)
	while a != 0:
		((q, a), b) = (divmod(b, a), a)
		(y0, y1) = (y1, y0 - q * y1)
		(x0, x1) = (x1, x0 - q * x1)
	return (b, x0, y0)

def lcm(a, b):
	d = gcd(a, b)
	return a * b // d

def modinv(a, m):
	(g, x, _) = xgcd(a, m)
	if g != 1:
		raise Exception('gcd(a, m) != 1')
	return x % m

def mod_add(x, y):
	x += y
	while x >= MOD:
		x -= MOD
	while x < 0:
		x += MOD
	return x

def mod_mul(x, y):
	return x * y % MOD

def mod_pow(x, y):
	if y == 0:
		return 1
	if y % 2:
		return mod_mul(x, mod_pow(x, y - 1))
	p = mod_pow(x, y // 2)
	return mod_mul(p, p)

def mod_inv(y):
	return mod_pow(y, MOD - 2)

def mod_div(x, y):
	return mod_mul(x, mod_inv(y))

def is_prime(n):
	if n == 1:
		return False
	for i in range(2, int(n ** 0.5) + 1):
		if n % i:
			return False
	return True

def gen_primes(n):
	P = [True for _ in range(n + 1)]
	P[0] = P[1] = False
	for i in range(int(n ** 0.5) + 1):
		if P[i]:
			for j in range(2 * i, n + 1, i):
				P[j] = False
	return P
main()


T = int(input())
for _ in range(T):
	(n, k) = map(int, input().split(' '))
	arr = [int(x) for x in input().split(' ')]
	arr.sort(reverse=True)
	ans = arr[0]
	del arr[0]
	if k > n - 1:
		k = n - 1
	for i in range(k):
		ans += arr[i]
	print(ans)


def func2(number):
	if number == 1:
		return (-1, 0, 0)
	if number == 2:
		return (-1, 0, 0)
	if number == 3:
		return (0, 0, 1)
	if number == 4:
		return (-1, 0, 0)
	if number == 5:
		return (0, 1, 0)
	if number == 6:
		return (0, 0, 2)
	if number == 7:
		return (1, 0, 0)
	if number == 8:
		return (0, 1, 1)
	if number == 9:
		return (0, 0, 3)
	if number == 10:
		return (0, 2, 0)
	if number == 11:
		return (0, 1, 2)
	if number == 12:
		return (0, 0, 4)
	if number == 13:
		return (0, 2, 1)
	if number == 14:
		return (2, 0, 0)
	if number == 15:
		return (0, 3, 0)
	if number == 16:
		return (0, 2, 2)
	if number == 17:
		return (1, 2, 0)
	if number == 18:
		return (0, 3, 1)
	if number == 19:
		return (0, 3, 3)
	if number == 20:
		return (0, 4, 0)

def func():
	n = int(input())
	n7 = 0
	n5 = 0
	n3 = 0
	if n <= 10:
		(n7, n5, n3) = func2(n)
	else:
		x = n % 10
		y = n // 10
		if x <= 4:
			y = y - 1
			x = x + 10
		(n7, n5, n3) = func2(x)
		n5 = n5 + y * 2
	if n7 == -1:
		print(-1)
		return
	print(n3, n5, n7)
	return

def codeforces1430ProblemB():
	x = [int(i) for i in input().split(' ')]
	n = x[0]
	k = x[1]
	tanks = []
	tanks = [int(i) for i in input().split(' ')]
	tanks = sorted(tanks)
	maxDiff = tanks[n - 1]
	if tanks[n - 1] == 0:
		print(0)
		return
	for i in range(k):
		maxDiff = maxDiff + tanks[n - 1 - (i + 1)]
	print(maxDiff)
	return
numTest = int(input())
while numTest:
	numTest -= 1
	codeforces1430ProblemB()


for i in range(int(input())):
	(n, k) = tuple(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	j = 2
	while k != 0:
		arr[n - 1] += arr[n - j]
		arr[n - j] = 0
		j += 1
		k -= 1
	diff = arr[n - 1] - arr[n - 2]
	print(diff)


import sys
from collections import defaultdict
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	lis = list(map(int, input().split()))
	lis.sort()
	for i in range(k):
		lis[-2] += lis[-1]
		lis.pop()
	print(lis[-1])


intInput = lambda : list(map(int, input().split()))

def main():
	test = int(input())
	while test > 0:
		test -= 1
		(n, k) = intInput()
		nums = intInput()
		print(sum(sorted(nums, reverse=True)[0:min(k + 1, n)]))
main()


a = int(input())
g = []
for i in range(1, a + 1):
	b = input().split(' ')
	b = [int(i) for i in b]
	c = input().split(' ')
	c = [int(i) for i in c]
	v = c.sort(reverse=True)
	sumliters = 0
	h = 0
	for i in range(0, b[1] + 1):
		sumliters += c[h]
		h += 1
	v = g.append(sumliters)
for i in g:
	print(i)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter
from itertools import combinations
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192
from sys import stderr

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def pow(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def gcd(a, b):
	if a == b:
		return a
	while b > 0:
		(a, b) = (b, a % b)
	return a

def prefix_sum(ar):
	return list(accumulate(ar))

def suffix_sum(ar):
	return list(accumulate(ar[::-1]))[::-1]
from collections import defaultdict

def numberOfSetBits(i):
	i = i - (i >> 1 & 1431655765)
	i = (i & 858993459) + (i >> 2 & 858993459)
	return ((i + (i >> 4) & 252645135) * 16843009 & 4294967295) >> 24

def N():
	return int(inp())

def solve():
	(n, k) = sep()
	ar = lis()
	ar.sort(reverse=True)
	print(sum(ar[:k + 1]))
testcase(int(inp()))


from sys import stdin
for _ in range(int(stdin.readline())):
	(n, k) = map(int, stdin.readline().split())
	array = list(map(int, stdin.readline().split()))
	sorts = sorted(array, reverse=True)
	ans = sorts[0]
	for i in range(1, k + 1):
		ans += sorts[i]
	print(ans)


for i in range(int(input())):
	(n, k) = list(map(int, input().split()))
	lst = list(map(int, input().split()))
	lst.sort()
	lst = lst[::-1]
	sum1 = 0
	for i in range(k + 1):
		sum1 += lst[i]
	print(sum1)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = sorted(map(int, input().split()))
	if arr[0] == arr[-1] == 0:
		print(0)
	else:
		ans = 0
		for i in range(k + 1):
			ans += arr[n - 1 - i]
		print(ans)


t = int(input())
res = []
for i in range(t):
	(n, k) = map(int, input().split())
	bar = [int(x) for x in input().split()]
	bar = sorted(bar, reverse=True)
	s = 0
	for j in range(k + 1):
		s += bar[j]
	res.append(s)
for i in range(t):
	print(res[i])


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, k) = map(int, input().split())
	A = sorted(map(int, input().split()), reverse=True)
	print(sum(A[:min(k + 1, n)]))


from collections import deque

def find(ar, k):
	n = len(ar)
	ar.sort()
	st = deque()
	for i in ar:
		st.append(i)
	max = st.pop()
	min = 0
	for _ in range(k):
		t = st.pop()
		max += t
	return max - min
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().rstrip().split())
	ar = list(map(int, input().rstrip().split()))
	if max(ar) == 0 and min(ar) == 0:
		print(0)
	else:
		print(find(ar, k))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	s = 0
	k = min(n - 1, k)
	while k + 1:
		s += a.pop()
		k -= 1
	print(s)


import sys
import math

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
t = II()
for q in range(t):
	(n, k) = MI()
	a = LI()
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


gans = []
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	u = list(map(int, input().split()))
	u.sort(reverse=1)
	if k > 0:
		ans = sum(u[:k + 1])
	else:
		ans = u[0] - u[-1]
	gans.append(ans)
print('\n'.join(map(str, gans)))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for j in range(int(input())):
	(n, k) = map(int, input().split())
	vals = list(map(int, input().split()))
	vals.sort()
	ans = vals.pop()
	for s in range(k):
		ans += vals.pop()
	print(ans)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	arr = arr[::-1]
	print(sum(arr[:min(k + 1, n)]))


def zip_sorted(a, b):
	(a, b) = zip(*sorted(zip(a, b)))
	sorted(zip(a, b), key=lambda x: x[1])
	return (a, b)
t = int(input())
for t1 in range(t):
	(n, k) = [int(n1) for n1 in input().split()]
	a = [int(n1) for n1 in input().split()]
	a = sorted(a, reverse=True)
	max1 = a[0]
	if k == 0:
		max1 = a[0] - a[-1]
		print(max1)
	else:
		for i in range(k):
			max1 = max1 + a[1 + i]
		print(max1)


T = int(input())
for t in range(T):
	st = input().split()
	n = int(st[0])
	k = int(st[1])
	st = input().split()
	A = []
	for i in range(n):
		A.append(int(st[i]))
	A = sorted(A, reverse=True)
	s = 0
	for i in range(min(k + 1, n)):
		s += A[i]
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	flag = n - 2
	while k > 0:
		a[n - 1] += a[flag]
		flag -= 1
		k -= 1
	print(a[n - 1] - 0)


m = int(input())
l = []
for i in range(m):
	(t, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	for i in range(len(a) - 2, len(a) - k - 2, -1):
		a[-1] += a[i]
		a[i] = 0
	l.append(a[-1])
for i in l:
	print(i)


def arrIn():
	return list(map(int, input().split()))

def mapIn():
	return map(int, input().split())
for ii in range(int(input())):
	(n, k) = mapIn()
	a = arrIn()
	a.sort()
	for i in range(n - 2, n - k - 2, -1):
		if i < 0:
			break
		a[n - 1] += a[i]
	print(a[n - 1])


t = int(input())
while t:
	t -= 1
	(n, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	ans = 0
	a.reverse()
	for i in range(k + 1):
		ans += a[i]
	print(ans)


t = int(input())
for i in range(t):
	line = [int(n) for n in input().split()]
	N = line[0]
	K = line[1]
	A = [int(n) for n in input().split()]
	A.sort(reverse=True)
	s = 0
	for j in range(K + 1):
		s += A[j]
	print(s)


loopcount = int(input())
for loop in range(loopcount):
	x = input()
	x = x.split(' ')
	x = list(map(int, x))
	y = input()
	y = y.split(' ')
	y = list(map(int, y))
	y.sort(reverse=True)
	print(sum(y[0:x[1] + 1:1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	if k == n:
		print(sum(a))
		continue
	m = min(a)
	a.sort(reverse=True)
	s = a.pop(0)
	for i in range(k):
		if a[i] != 0:
			s += a[i]
			m = 0
		else:
			break
	print(s - m)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def main():
	for _ in range(readint()):
		(n, k) = readints()
		arr = readarri()
		arr.sort(reverse=True)
		for i in range(k):
			arr[i + 1] += arr[i]
			arr[i] = 0
		print(max(arr) - min(arr))
main()


import sys
import heapq

class Solution:

	def process(self, N, K, A):
		A.sort()
		(mn, mx) = (A[0], A[-1])
		for i in range(K):
			mx += A[N - 2 - i]
			mn = 0
		print(mx - mn)

	def read_int_arr(self, s):
		return [int(x) for x in s.split(' ')]

	def parse(self, lines):
		n = int(lines[0])
		for i in range(n):
			(N, K) = self.read_int_arr(lines[1 + 2 * i])
			A = self.read_int_arr(lines[1 + 2 * i + 1])
			self.process(N, K, A)

def main():
	Solution().parse(sys.stdin.readlines())
main()


def ans(a, n, k):
	if k >= n - 1:
		return sum(a)
	a.sort()
	i = len(a) - 2
	val = a[-1]
	x = 0
	while x < k:
		x += 1
		val += a[i]
		i -= 1
	return val
m = int(input())
for j in range(m):
	y = input().split()
	n = int(y[0])
	k = int(y[1])
	x = input().split()
	a = []
	for i in x:
		a.append(int(i))
	print(ans(a, n, k))


def getint():
	return [int(i) for i in input().split()]

def get():
	return int(input())

def S():
	for test in range(int(input())):
		solve()

def solve():
	(n, k) = getint()
	a = getint()
	a.sort(reverse=True)
	res = 0
	for i in range(k + 1):
		res += a[i]
	if k == 0:
		print(a[0] - a[-1])
		return
	print(res)
S()


for i in range(int(input())):
	(n, k) = map(int, input().split())
	barrels = list(map(int, input().split()))
	barrels.sort(reverse=True)
	amount = barrels[0]
	for i in range(k):
		amount += barrels[i + 1]
	print(amount)


t = 1
t = int(input())
while t:
	t -= 1
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	(mini, maxi) = (a[-1], a[0])
	for i in range(min(k, n - 1)):
		maxi += a[i + 1]
		mini = 0
	print(maxi - mini)


t = int(input())
L = []
for i in range(t):
	(n, k) = input().split()
	A = input()
	A = [int(i) for i in A.split(' ') if i.isdigit()]
	A = sorted(A, reverse=True)
	S = 0
	for i in range(int(k) + 1):
		S += int(A[i])
	L.append(S)
for i in range(len(L)):
	print(L[i])


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
enum = enumerate
inf = float('inf')
cdiv = lambda x, y: -(-x // y)
_T_ = inin()
for _t_ in range(_T_):
	(n, k) = inar()
	a = inar()
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	l1 = l[n - k - 1:]
	print(sum(l1))


t = int(input())
for _ in range(t):
	[n, k] = [int(s) for s in input().split()]
	a = [int(s) for s in input().split()]
	a.sort()
	d = 0
	for i in range(n - k - 1, n - 1):
		d = d + a[i]
	print(d + a[n - 1])


from sys import stdin
input = stdin.readline

def solve():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	print(sum(a[:k + 1]))
t = int(input())
for _ in range(t):
	solve()


def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def inn():
	return int(input())
for _ in range(inn()):
	(n, k) = value()
	a = arr()
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	mx = arr[0]
	arr = arr[1:]
	for j in range(k):
		mx += arr[j]
		arr[j] = 0
	print(mx - min(arr))


import sys
from sys import stdin, stdout
import math
import random
import heapq
from collections import Counter
from functools import lru_cache
try:
	for _ in range(int(input())):
		(n, k) = map(int, input().split())
		arr = [int(i) for i in input().split()]
		arr.sort()
		for i in range(n - 2, -1, -1):
			if arr[i] != 0 and k > 0:
				arr[n - 1] += arr[i]
				k -= 1
				if k == 0:
					break
		print(arr[n - 1])
except EOFError as e:
	print(e)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	L = sorted(list(map(int, input().split())))
	print(sum(L[len(L) - k - 1:]))


t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if n == 1:
		print(0)
		continue
	p = a[-1]
	j = n - 2
	while j >= 0:
		if k > 0:
			p = p + a[j]
			k = k - 1
		else:
			break
		j = j - 1
	print(p)


from sys import stdin
casos = int(stdin.readline().strip())
for caso in range(casos):
	(n, k) = map(int, stdin.readline().strip().split())
	s = list(map(int, stdin.readline().strip().split()))
	s.sort()
	mx = s[-1]
	for i in range(n - 2, -1, -1):
		if k > 0:
			mx += s[i]
			s[i] = 0
			k -= 1
	print(mx - min(s))


for tt in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	print(sum(l[n - k - 1:n - 1]) + l[n - 1])


for _ in range(0, int(input())):
	(n, k) = map(int, input().split())
	if n == 0:
		print(0)
		continue
	l1 = list(map(int, input().split()))
	if sum(l1) == 0:
		print(0)
		continue
	if k == 0 or n == 1:
		print(max(l1) - min(l1))
		continue
	i = 1
	l1.sort()
	l1.reverse()
	while k != 0:
		l1[0] += l1[i]
		l1[i] = 0
		i += 1
		k -= 1
	print(max(l1) - min(l1))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort(reverse=True)
	while n > 0 and arr[-1] == 0:
		arr.pop(-1)
		n -= 1
	for i in range(min(k, n - 1)):
		arr[0] = arr[0] + arr[i + 1]
	if n == 0:
		print(0)
	else:
		print(arr[0])


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	i = n - 2
	total = arr[n - 1]
	if k == 0:
		print(arr[n - 1] - arr[0])
	else:
		while k > 0 and i > -1:
			total += arr[i]
			k -= 1
			i -= 1
		print(total)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	maxb = a[n - 1]
	a[n - 1] = 0
	ind = n - 2
	while k != 0:
		maxv = a[ind]
		maxb += maxv
		a[ind] = 0
		ind -= 1
		k -= 1
	print(maxb)


t = int(input())

def result(barrels, k, n):
	barrels.sort()
	if k == 0:
		return barrels[n - 1] - barrels[0]
	else:
		maxi = 0
		for i in range(k + 1):
			maxi += barrels[n - 1 - i]
		return maxi
for i in range(t):
	(n, k) = tuple(map(int, input().split()))
	barrels = [int(x) for x in input().split()]
	print(result(barrels, k, n))


for t in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted([int(i) for i in input().split()])
	m = sum(a[n - k - 1:n])
	print(m)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	c = l[0]
	if k == 0:
		print(l[0] + l[1])
	for i in range(1, n):
		if i - 1 == k:
			break
		c += l[i]
		l[i] = 0
	print(c)


def solve(n, k, a):
	if a[-1] == 0:
		return 0
	if k >= n - 1:
		return sum(a)
	c = 0
	for i in range(n - 2, n - 2 - k + 1, -1):
		c += a[i]
	ans1 = c + a[-1] + a[0]
	c = 0
	for i in range(n - 2, n - 2 - k, -1):
		c += a[i]
	ans1 = max(ans1, c + a[-1])
	return ans1
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	print(solve(n, k, a))


for _ in range(int(input())):
	(N, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr = sorted(arr)
	arr.reverse()
	ans = 0
	for i in range(k + 1):
		ans += arr[i]
	print(ans)


for _ in range(int(input())):
	(n, k) = [int(x) for x in input().split()]
	arr = [int(x) for x in input().split()]
	if k >= n - 1:
		print(sum(arr))
	else:
		arr.sort()
		for i in range(n - 2, n - k - 2, -1):
			arr[-1] += arr[i]
		print(arr[-1])


for _ in ' ' * int(input()):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	s = a[-1]
	a.pop()
	i = 0
	while i < k and len(a) != 0:
		s += a[-1]
		a.pop()
		i += 1
	print(s)


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	s = sum(a)
	if not s:
		print(0)
	elif n == 1:
		print(0)
	else:
		a.sort(reverse=True)
		s = a[0]
		z = 1
		while k > 0:
			s += a[z]
			z += 1
			k -= 1
		print(s)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def prod(a, mod=10 ** 9 + 7):
	ans = 1
	for each in a:
		ans = ans * each % mod
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	cur = 0
	for i in range(n - 2, -1, -1):
		cur += 1
		a[n - 1] += a[i]
		a[i] = 0
		if cur == k:
			break
	print(max(a) - min(a))


for case in range(int(input())):
	(n, k) = list(map(int, str.split(input())))
	a = list(map(int, str.split(input())))
	a.sort(reverse=True)
	if a[0] == 0:
		print(0)
	else:
		rslt = sum(a[:k + 1])
		print(rslt)


from math import gcd
from bisect import bisect_left, bisect_right
from itertools import combinations
from itertools import permutations
from bisect import bisect_left
from math import ceil
from math import radians
from heapq import heapify, heappush, heappop, nsmallest
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
from fractions import Fraction
mod = int(pow(10, 9) + 7)

def ii():
	return int(input())

def si():
	return str(input())

def mi():
	return map(int, input().split())

def li1():
	return list(mi())

def fii():
	return int(stdin.readline())

def fsi():
	return str(stdin.readline())

def fmi():
	return map(int, stdin.readline().split())

def fli():
	return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

def getKey(item):
	return item[0]

def sort2(l):
	return sorted(l, key=getKey)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000

def bfs(d, v):
	q = []
	q.append(v)
	visited[v] = 1
	while len(q) != 0:
		x = q[0]
		q.pop(0)
		for i in d[x]:
			if visited[i] != 1:
				visited[i] = 1
				q.append(i)
		print(x)

def make_graph(e):
	d = {}
	for i in range(e):
		(x, y) = mi()
		if x not in d:
			d[x] = [y]
		else:
			d[x].append(y)
		if y not in d:
			d[y] = [x]
		else:
			d[y].append(x)
	return d

def gr2(n):
	d = defaultdict(list)
	for i in range(n):
		(x, y) = mi()
		d[x].append(y)
	return d

def connected_components(graph):
	seen = set()

	def dfs(v):
		vs = set([v])
		component = []
		while vs:
			v = vs.pop()
			seen.add(v)
			vs |= set(graph[v]) - seen
			component.append(v)
		return component
	ans = []
	for v in graph:
		if v not in seen:
			d = dfs(v)
			ans.append(d)
	return ans

def primeFactors(n):
	s = set()
	while n % 2 == 0:
		s.add(2)
		n = n // 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0 and i % 2 == 1:
			s.add(i)
			n = n // i
	if n > 2 and n % 2 == 1:
		s.add(n)
	return s

def find_all(a_str, sub):
	start = 0
	while True:
		start = a_str.find(sub, start)
		if start == -1:
			return
		yield start
		start += len(sub)

def SieveOfEratosthenes(n, isPrime):
	isPrime[0] = isPrime[1] = False
	for i in range(2, n):
		isPrime[i] = True
	p = 2
	while p * p <= n:
		if isPrime[p] == True:
			i = p * p
			while i <= n:
				isPrime[i] = False
				i += p
		p += 1
	return isPrime

def dijkstra(edges, f, t):
	g = defaultdict(list)
	for (l, r, c) in edges:
		g[l].append((c, r))
	(q, seen, mins) = ([(0, f, ())], set(), {f: 0})
	while q:
		(cost, v1, path) = heappop(q)
		if v1 not in seen:
			seen.add(v1)
			path = (v1, path)
			if v1 == t:
				return (cost, path)
			for (c, v2) in g.get(v1, ()):
				if v2 in seen:
					continue
				prev = mins.get(v2, None)
				next = cost + c
				if prev is None or next < prev:
					mins[v2] = next
					heappush(q, (next, v2, path))
	return float('inf')

def binsearch(a, l, r, x):
	while l <= r:
		mid = l + (r - 1) // 2
		if a[mid]:
			return mid
		elif a[mid] > x:
			l = mid - 1
		else:
			r = mid + 1
	return -1

def readTree(n):
	adj = [set() for _ in range(n)]
	for _ in range(n - 1):
		(u, v) = map(int, input().split())
		adj[u - 1].add(v - 1)
		adj[v - 1].add(u - 1)
	return adj

def treeOrderByDepth(n, adj, root=0):
	parent = [-2] + [-1] * (n - 1)
	ordered = []
	q = deque()
	q.append(root)
	depth = [0] * n
	while q:
		c = q.popleft()
		ordered.append(c)
		for a in adj[c]:
			if parent[a] == -1:
				parent[a] = c
				depth[a] = depth[c] + 1
				q.append(a)
	return (ordered, parent, depth)

def isSubSequence(str1, str2):
	m = len(str1)
	n = len(str2)
	j = 0
	i = 0
	while j < m and i < n:
		if str1[j] == str2[i]:
			j = j + 1
		i = i + 1
	return j == m

def nextPowerOf2(n):
	count = 0
	if n and (not n & n - 1):
		return n
	while n != 0:
		n >>= 1
		count += 1
	return 1 << count

def cou(n):
	c = 0
	while n > 1:
		c += 1
		n //= 2
	return c

def sortsec(l):
	return sorted(l, key=lambda x: x[1])

def BinarySearch(a, x):
	i = bisect_left(a, x)
	if i:
		return i - 1
	else:
		return -1

def subarray(A):
	r = set()
	p = {0}
	for x in A:
		p = {x | y for y in p} | {x}
		r |= p
	return len(r)

def setBitNumber(n):
	n |= n >> 1
	n |= n >> 2
	n |= n >> 4
	n |= n >> 8
	n |= n >> 16
	n = n + 1
	return n >> 1

def countSetBits(n):
	count = 0
	while n:
		count += n & 1
		n >>= 1
	return count
for _ in range(ii()):
	(n, k) = mi()
	l = sorted(li1())[::-1]
	print(sum(l[:k + 1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	arr = list(map(int, input().split(' ')))
	arr.sort()
	if n == 1:
		print(0)
	else:
		sum1 = max(arr)
		val = arr[:n - 1]
		val.sort(reverse=True)
		for i in range(k):
			sum1 += val[i]
		print(sum1)


import sys
sys.setrecursionlimit(10000000)
mod = 10 ** 9 + 7
INF = float('inf')
from sys import stdin
readline = stdin.readline

def readInts():
	return list(map(int, readline().split()))

def readTuples():
	return tuple(map(int, readline().split()))

def I():
	return int(readline())
t = I()
for _ in range(t):
	(n, k) = readInts()
	A = readInts()
	S = sorted(A)
	nya = max(S)
	S = S[:-1]
	print(nya + sum(S[-k:]))


t = int(input())
for g in range(t):
	(n, k) = map(int, input().split())
	a = sorted([int(x) for x in input().split()], reverse=True)
	uusa = a[1:min(n - 1, k) + 1]
	maks = a[0] + sum(uusa)
	print(maks)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	(n, k) = invr()
	a = inara()
	a.sort()
	for i in range(n - 2, -1, -1):
		if k > 0:
			a[n - 1] += a[i]
			a[i] = 0
			k -= 1
	a.sort()
	print(a[-1] - a[0])


t = int(input())
while t != 0:
	t -= 1
	(n, k) = [int(x) for x in input().split()]
	a = [int(y) for y in input().split()]
	a.sort(reverse=True)
	sum = a[0]
	i = 1
	while k != 0:
		sum += a[i]
		i += 1
		k -= 1
	print(sum)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	if k == 0:
		print(max(l) - min(l))
	else:
		l.sort(reverse=True)
		s = 0
		for i in range(k + 1):
			s += l[i]
		print(s)


def main():
	t = int(input())
	for __ in range(t):
		(n, k) = map(int, input().split())
		A = sorted([int(num) for num in input().split()], reverse=True)
		s = A[0]
		for i in A[1:min(k, n) + 1]:
			s += i
		print(s)
main()


n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	al = list(map(int, input().split()))
	al.sort(reverse=True)
	res = sum(al[:b + 1])
	print(res)


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort(reverse=True)
	result = l[0]
	for i in range(1, n):
		if k <= 0:
			break
		else:
			result += l[i]
			k -= 1
	print(result)


from math import *
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
inp = lambda : int(input())
li = lambda : list(map(int, input().split()))
ls = lambda : list(input())
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def solve():
	for _ in range(inp()):
		(n, k) = li()
		a = li()
		a.sort(reverse=True)
		print(sum(a[:k + 1]))
solve()


def rl():
	return list(map(int, input().split()))

def arp(arr):
	return ' '.join([str(i) for i in arr])
for _ in range(int(input())):
	(n, k) = rl()
	arr = rl()
	arr.sort()
	if all((i == 0 for i in arr)):
		print(0)
	elif k == 0:
		print(max(arr) - min(arr))
	else:
		arr = sorted([i for i in arr if i != 0])
		arr = arr[::-1]
		print(sum(arr[:k + 1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split(' '))
	arr = [int(num) for num in input().split(' ')]
	arr.sort(reverse=True)
	x = sum(arr[0:k + 1])
	ans = x
	print(ans)


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort(reverse=True)
	print(sum(a[:k + 1]))


import math
t = int(input())
for q in range(t):
	(n, k) = [int(i) for i in input().split()]
	L = [int(i) for i in input().split()]
	L.sort()
	s = 0
	if k == 0:
		print(max(L) - min(L))
		continue
	for i in range(n - 1, n - k - 2, -1):
		s += L[i]
	print(s)


t = int(input())
while t > 0:
	l1 = input().split()
	n = int(l1[0])
	k = int(l1[1])
	a = []
	l2 = input().split()
	for i in l2:
		a.append(int(i))
	a.sort()
	i = 1
	while i <= k and i < n:
		a[n - 1] += a[n - i - 1]
		i += 1
	print(a[n - 1])
	t = t - 1


from collections import *
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	L = list(map(int, input().split()))
	L.sort()
	print(sum(L[-1 - k:-1]) + L[-1])


for test in range(int(input())):
	(n, k) = list(map(int, input().split()))
	brs = list(map(int, input().split()))[:n]
	if max(brs) == 0:
		print(0)
	else:
		brs.sort(reverse=True)
		res = sum(brs[:k + 1])
		print(res)


t = int(input())
for i in range(t):
	nk = list(map(int, input().split()))
	n = nk[0]
	k = nk[1]
	a = list(map(int, input().split()))
	ans = 0
	if k >= n - 1:
		ans = sum(a)
	else:
		a.sort()
		ans = sum(a[len(a) - k - 1:len(a)])
	print(ans)


t = int(input())
while t > 0:
	i = input().split()
	(n, k) = (int(i[0]), int(i[1]))
	water = [int(x) for x in input().split()]
	water.sort(reverse=True)
	s = 0
	for x in range(k + 1):
		s += water[x]
	print(s)
	t -= 1


t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	x = sorted(map(int, input().split()))
	s = sum(x[-k - 1:])
	print(s)


from math import *
import threading
import sys
mod = 10 ** 9 + 7

def npr(n, r):
	return factorial(n) // factorial(n - r) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = -1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def graph(n, m):
	adj = dict()
	for i in range(1, n + 1):
		adj.setdefault(i, 0)
	for i in range(m):
		(a, b) = map(int, input().split())
		adj[a] += 1
		adj[b] += 1
	return adj

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	li = []
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, len(prime)):
		if prime[p]:
			li.append(p)
	return li
sys.setrecursionlimit(300000)
for _ in range(int(input()) if True else 1):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	steps = min(n - 1, k)
	for i in range(1, steps + 1):
		a[0] += a[i]
	print(a[0])


import sys
lines = sys.stdin.readlines()
cur_line = -1

def input():
	global lines, cur_line
	cur_line += 1
	return lines[cur_line][:-1]

def solve():
	(n, k) = map(int, input().split())
	nums = list(map(int, input().split()))
	nums.sort()
	nums.reverse()
	print(sum(nums[:k + 1]))
for _ in range(int(input())):
	solve()


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	ar = list(map(int, input().split()))
	ar.sort()
	if n == 1:
		print(0)
	else:
		ma = ar[-1]
		if k == 0:
			print(max(ar) - min(ar))
		else:
			for i in range(2, n + 1):
				if k != 0:
					if ar[-i] == 0:
						break
					else:
						ma += ar[-i]
						k -= 1
				else:
					break
			print(ma)


t = int(input())
for case in range(t):
	inp = list(map(int, str.split(input(), ' ')))
	s = list(map(int, str.split(input(), ' ')))
	n = inp[0]
	k = inp[1]
	s.sort()
	if s.count(0) == n:
		print(0)
	elif k < n:
		for i in range(n - 2, n - 2 - k, -1):
			s[n - 1] += s[i]
		print(s[n - 1])
	else:
		for i in range(n - 2, -1, -1):
			s[n - 1] += s[i]
		print(s[n - 1])


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		(n, k) = inar()
		arr = inar()
		arr.sort()
		take = arr[-1]
		for i in range(n - 2, -1, -1):
			if k == 0:
				break
			else:
				arr[-1] += arr[i]
				arr[i] = 0
				k -= 1
		print(max(arr) - min(arr))
main()


t = int(input())
for case in range(t):
	(n, k) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	a.sort()
	ans = a[-1] + sum(a[-(k + 1):-1])
	print(ans)


import math
import copy
t = int(input())
for _ in range(t):
	(n, k) = map(int, input().split())
	inp = [int(i) for i in input().split()]
	inp.sort()
	s = 0
	for i in range(n - 2, -1, -1):
		s = s + inp[i]
		k = k - 1
		if k == 0:
			break
	print(inp[n - 1] + s)


for i in range(int(input())):
	(n, k) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	for j in range(k):
		a[len(a) - 1] += a[len(a) - j - 2]
	print(a[len(a) - 1])


def process():
	(n, k) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	if k > n - 1:
		k = n - 1
	arr = sorted(arr, reverse=True)
	print(sum(arr[0:k + 1]))

def main():
	for i in range(int(input())):
		process()
main()


iin = lambda : int(input())
lin = lambda : list(map(int, input().rstrip().split()))
TEST_CASES = True

def main():
	(n, k) = lin()
	a = lin()
	if n == 1:
		print(a[0])
	else:
		a.sort()
		i = n - 2
		while k:
			a[-1] += a[i]
			i -= 1
			k -= 1
		print(a[-1])
if not TEST_CASES:
	main()
else:
	[main() for _ in range(int(input()))]


t = int(input())
cases = []
for i in range(t):
	(n, k) = map(int, input().split())
	a = [int(x) for x in input().split()]
	cases.append([n, k, a])
for (n, k, a) in cases:
	a.sort()
	a.reverse()
	print(sum(a[:k + 1]))


from math import *
t = int(input())
while t:
	t = t - 1
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	j = n - 2
	for i in range(k):
		a[n - 1] += a[j]
		j = j - 1
	print(a[n - 1])


def solve(arr, k):
	arr.sort()
	return sum(arr[len(arr) - k - 1:])
for t in range(int(input())):
	(n, k) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(arr, k))


import heapq
T = int(input())
for t in range(T):
	(n, k) = list(map(int, list(input().split())))
	x = [-int(i) for i in input().split()]
	heapq.heapify(x)
	c = heapq.heappop(x)
	for _ in range(k):
		c += heapq.heappop(x)
	print(-c)


t = int(input())
while t:
	t -= 1
	(n, k) = input().split()
	(n, k) = (int(n), int(k))
	arr = [int(i) for i in input().split()]
	arr.sort()
	sum = 0
	for i in range(n - 2, max(n - 1 - k - 1, -1), -1):
		sum += arr[i]
	print(arr[len(arr) - 1] + sum)


for i in range(int(input())):
	print((lambda k, m: sum(m[-k - 1:]))(list(map(int, input().split()))[1], sorted(list(map(int, input().split())))))


c = int(input())
for x in range(c):
	(n, k) = map(int, input().split())
	ls = list(map(int, input().split()))
	ls.sort(reverse=True)
	s = sum(ls[:k + 1])
	print(s)


count = int(input())
for iter in range(count):
	(n, k) = map(int, input().split())
	A = list(map(int, input().split()))
	A.sort(reverse=1)
	sum = 0
	for i in range(k + 1):
		sum += A[i]
	print(sum)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	l1 = list(map(int, input().split()))
	if k == 0:
		print(max(l1) - min(l1))
	elif k >= n - 1:
		print(sum(l1))
	else:
		l1.sort(reverse=True)
		print(sum(l1[:k + 1]))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	cur = n - 2
	while k > 0 and cur >= 0:
		a[n - 1] += a[cur]
		cur -= 1
		k -= 1
	print(0 if n == 1 else a[n - 1])


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	barells = sorted(list(map(int, input().split())))
	Sum = 0
	for i in range(k + 2)[2:]:
		Sum = barells[-1] + barells[-i]
		barells[-1] = Sum
		barells[-i] = 0
	raznica = Sum - min(barells)
	print(raznica)


for t in range(int(input())):
	(n, k) = map(int, input().split())
	l = sorted(map(int, input().split()), reverse=True)
	print(sum(l[:k + 1]))


t = int(input())
for i in range(t):
	(n, k) = [int(i) for i in input().split()]
	l = [int(i) for i in input().split()]
	if set(l) == {0}:
		print(0)
	else:
		z = sorted(l)
		z.reverse()
		s = z[0]
		for i in range(1, k + 1):
			s = s + z[i]
		print(s)


import sys
(barrels, pour_count) = (0, 0)

def solve(sorted_configuration: list, barrel_count: int, pour_left: int) -> int:
	summing = 0
	while pour_left > 1:
		if len(sorted_configuration) > 0:
			summing += sorted_configuration.pop()
		pour_left -= 1
	if len(sorted_configuration) == 0:
		return summing
	if pour_left == 1:
		summing += sorted_configuration[-1] if len(sorted_configuration) == 1 else sorted_configuration[-1] + sorted_configuration[-2]
	return summing
for (count, line) in enumerate(sys.stdin):
	if count == 0:
		continue
	if count % 2 == 1:
		(barrels, pour_count) = [int(i) for i in line.split(' ')]
		continue
	data = [int(i) for i in line.split(' ')]
	data.sort()
	print(solve(data, barrels, pour_count))


n1 = int(input())
for _ in range(n1):
	(n2, k) = map(int, input().split())
	a = list(map(int, input().strip().split()))[:n2]
	a.sort()
	for i in range(n2):
		if k > 0:
			a[n2 - 1] = a[n2 - 1] + a[n2 - 2 - i]
			k = k - 1
			a[n2 - 2 - i] = 0
	print(max(a) - min(a))


for _ in range(int(input())):
	(n, k) = map(int, input().split())
	b = list(map(int, input().split()))
	b.sort(reverse=True)
	if k <= n:
		s = sum(b[1:1 + k])
	else:
		s = sum(b[1:])
	print(b[0] + s)


t = int(input())
cases = []
for i in range(t):
	(n, k) = map(int, input().strip().split())
	cases.append((k, list(map(int, input().strip().split()))))

def solve(case):
	(k, b) = case
	b.sort()
	if k == 0:
		return b[-1] - b[0]
	else:
		return sum(b[-k - 1:])
for case in cases:
	print(solve(case))


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print(x):
	sys.stdout.write(str(x) + '\n')
t = int(input())
for i in range(t):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	ma = sum(a[:k + 1])
	print(ma)


for t in range(int(input())):
	(n, k) = list(map(int, input().split()))
	a = list(map(int, input().split()))
	a.sort(reverse=True)
	if max(a) == 0:
		print(0)
	else:
		s = 0
		for i in range(k + 1):
			s += a[i]
		print(s)


import random

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def lcm(a, b):
	return a * b / gcd(a, b)
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	a.reverse()
	print(sum(a[0:min(n, k + 1)]))


t = int(input())
for j in range(t):
	s = 0
	(l, n) = map(int, input().split())
	a = list(map(int, input().split()))
	a = sorted(a)
	for i in range(1, n + 2):
		s += a[-i]
	print(s)


from math import *
import sys, random

def nextInt():
	return int(input())

def nextStrs():
	return input().split()

def nextInts():
	return list(map(int, nextStrs()))

def main():
	t = nextInt()
	while t > 0:
		(n, k) = nextInts()
		arr = nextInts()
		arr.sort()
		arr.reverse()
		for i in range(1, min(n, k + 1)):
			arr[0] += arr[i]
			arr[i] = 0
		mx = 0
		mn = 10 ** 9 + 7
		for i in range(n):
			mn = min(mn, arr[i])
			mx = max(mx, arr[i])
		print(mx - mn)
		t -= 1
exit(main())


t = int(input())
for z in range(t):
	(n, k) = [int(q) for q in input().split()]
	a = sorted([int(q) for q in input().split()], reverse=True)
	c = a[0]
	for i in range(k):
		c += a[i + 1]
	print(c)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(getint()):
		(_, k) = getints()
		print(sum(sorted(getints(), reverse=True)[:k + 1]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def getint():
	return int(input())

def getints():
	return list(map(int, input().split()))

def getint1():
	return list(map(lambda x: int(x) - 1, input().split()))
main()


for tca in range(int(input())):
	(n1, k) = map(int, input().split())
	a = [int(i) for i in input().split()]
	a.sort()
	ans = 0
	a.reverse()
	for i in range(k + 1):
		ans += a[i]
	print(ans)


import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
	(n, k) = list(map(int, sys.stdin.readline().strip().split()))
	a = list(map(int, sys.stdin.readline().strip().split()))
	a.sort()
	a.reverse()
	print(sum(a[:k + 1]))


from collections import Counter
import operator
for _ in range(int(input())):
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))
	b = Counter(a)
	b = sorted(b.items(), key=operator.itemgetter(0), reverse=True)
	v = b[0][0]
	v += min(k, b[0][1] - 1) * b[0][0]
	k -= min(k, b[0][1] - 1)
	for i in range(1, len(b)):
		if k == 0:
			break
		v = v + min(k, b[i][1]) * b[i][0]
		k -= min(k, b[i][1])
	print(v)