#include <bits/stdc++.h>
using namespace std;
const long long maxn = 5e5 + 7;
const long long mod = 1e9 + 7;
const long long INF = 1e9 + 7;
const long long mlog = 20;
const long long SQ = 400;
long long a[maxn];
int32_t main() {
  ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
  ;
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, k;
    cin >> n >> k;
    for (long long i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for (long long i = n - 2; i >= 0; i--)
      if (k > 0) a[n - 1] += a[i], a[i] = 0, k--;
    if (a[n - 2] == 0)
      cout << a[n - 1] - a[n - 2] << "\n";
    else
      cout << a[n - 1] - a[0] << "\n";
  }
  return 0;
}
