#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, k, x, curr1, curr2;
  multiset<long long> s;
  cin >> t;
  while (t--) {
    cin >> n >> k;
    while (n--) {
      cin >> x;
      s.insert(x);
    }
    auto itend = s.end();
    itend--;
    auto itbeforend = itend;
    itbeforend--;
    while (k--) {
      curr1 = *itend;
      curr2 = *itbeforend;
      curr2 += curr1;
      s.erase(itend);
      s.erase(itbeforend);
      s.insert(curr2);
      s.insert(0);
      itend = s.end();
      itend--;
      itbeforend = itend;
      itbeforend--;
    }
    auto itbegin = s.begin();
    cout << *itend - *itbegin << endl;
    s.clear();
  }
}
