#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int x = 0, f = 1;
  while ((c < '0' || c > '9') && c - '-') c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') {
    x = (x << 3) + (x << 1) + c - 48;
    c = getchar();
  }
  return x * f;
}
const int N = 2e5 + 10;
int t, n, a[N], k;
long long sum = 0;
int main() {
  t = read();
  while (t--) {
    n = read();
    k = read();
    for (int i = 1; i <= n; i++) a[i] = read();
    sort(a + 1, a + n + 1);
    for (int i = n; i >= n - k; i--) sum += a[i];
    cout << sum << "\n";
    sum = 0;
  }
  return 0;
}
