#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  while (t--) {
    long long int n, k;
    cin >> n >> k;
    long long int i, arr[n];
    for (i = 0; i < n; i++) cin >> arr[i];
    sort(arr, arr + n, greater<int>());
    long long int max = arr[0], min = 0, ans = 0;
    for (i = 1; i <= k; i++) {
      max += arr[i];
      arr[i] = 0;
    }
    sort(arr, arr + n);
    min = arr[0];
    ans = max - min;
    cout << ans << endl;
  }
}
