#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, k, mx = 0, mn = 0, ans = 0;
    scanf("%lld %lld", &n, &k);
    int a[n + 5];
    for (int i = 0; i < n; i++) {
      scanf("%lld", &a[i]);
    }
    sort(a, a + n);
    mx = a[n - 1];
    mn = a[0];
    for (int i = n - 2; i >= 0; i--) {
      if (k > 0) {
        mx += a[i];
        a[i] = 0;
        mn = 0;
        k--;
      } else {
        break;
      }
    }
    ans = mx - mn;
    printf("%lld\n", ans);
  }
  return 0;
}
