#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void _IOS() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
}
long long a[500009], b[500009];
long long n, m, k;
map<long long, bool> pg;
long long dp[100009][3];
int main() {
  _IOS();
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int i = n - 2;
    while (i >= 0 && k--) {
      a[n - 1] += a[i];
      a[i] = 0;
      i--;
    }
    long long mn = (long long)1e10, mx = 0;
    for (int i = 0; i < n; i++) {
      mn = min(a[i], mn);
      mx = max(a[i], mx);
    }
    cout << abs(mx - mn) << endl;
  }
}
