#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long T;
  cin >> T;
  while (T-- != 0) {
    int n, k;
    cin >> n >> k;
    long long int arr[n];
    for (int i = 0; i < n; ++i) {
      cin >> arr[i];
    }
    sort(arr, arr + n);
    long long int ans = 0;
    if (k == 0) {
      ans = arr[n - 1] - arr[0];
    } else {
      int mn = min(k, n - 1);
      ans = arr[n - 1];
      for (int i = n - 2; i >= n - mn - 1; i--) {
        ans += arr[i];
      }
    }
    cout << ans << '\n';
  }
  return 0;
}
