#include <bits/stdc++.h>
using namespace std;
void redirect_io() { freopen("input", "r", stdin); }
void fast_io() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  fast_io();
  int t, n, x = 0, y = 0, z, k;
  long long ans;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    vector<long long> ar(n);
    for (int i = 0; i < n; i++) {
      cin >> ar[i];
    }
    if (n == 1) {
      cout << 0 << "\n";
      continue;
    }
    sort(ar.begin(), ar.end());
    if (k == 0) {
      cout << ar[n - 1] - ar[0] << "\n";
      continue;
    }
    ans = ar[n - 1];
    for (int i = 1; i <= k; i++) {
      if (n - 1 - i >= 0) {
        ans += ar[n - i - 1];
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
