#include <bits/stdc++.h>
using namespace std;
int n;
int k;
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> k;
    multiset<long long> a;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      a.insert(x);
    }
    while (k-- > 0) {
      long long mx = *--a.end();
      a.erase(--a.end());
      long long mx2 = *--a.end();
      a.erase(--a.end());
      a.insert(mx + mx2);
    }
    cout << *--a.end() << "\n";
  }
}
