#include <bits/stdc++.h>
const int N = (int)1e5 + 7;
const int MOD = (int)1e9 + 7;
const long long INF = (long long)1e18;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long n, k, res = 0;
    cin >> n >> k;
    vector<long long> A(n);
    for (int i = 0; i < n; i++) cin >> A[i];
    sort(A.begin(), A.end());
    long long l = 0, r = n - 2;
    while (k-- && l <= r) {
      if (A[l] < A[r]) {
        res += A[r];
        r--;
      } else {
        res += A[l];
        l++;
      }
    }
    res += A[n - 1];
    cout << res << '\n';
  }
  return 0;
}
