#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(228);
const double EPS = 1e-7;
const double PI = acos(-1);
void solve();
signed main() {
  ios_base::sync_with_stdio(false);
  solve();
  exit(0);
}
void solve() {
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    for (int i = n - 2; i >= 0 && k > 0; i--) {
      a.back() += a[i];
      a[i] = 0;
      k--;
    }
    cout << a.back() - *min_element(a.begin(), a.end()) << '\n';
  }
}
