#include <bits/stdc++.h>
using namespace std;
long long int nCr1[1001][1001];
long long int nCr(long long int n, long long int r) {
  if (nCr1[n][r]) return nCr1[n][r];
  if (r == 1) return nCr1[n][r] = n;
  if (n == r) return nCr1[n][r] = 1;
  if (r == 0) return nCr1[n][r] = 1;
  return nCr1[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1)) % 1000000007;
}
bool prime(long long int n) {
  long long int i;
  for (i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return false;
  }
  return true;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, n, k, i, s;
  cin >> t;
  while (t > 0) {
    cin >> n >> k;
    long long int a[n];
    for (i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    if (k == 0)
      cout << a[n - 1] - a[0];
    else {
      i = n - 2;
      s = a[n - 1];
      while (k > 0) {
        s += a[i];
        i--;
        k--;
      }
      cout << s;
    }
    cout << endl;
    t--;
  }
}
