#include <bits/stdc++.h>
using std::max;
using std::min;
using std::swap;
using std::vector;
const int N = 2e5 + 5;
int n, m;
long long t;
int p[N], val[N];
long long getint() {
  long long X = 0, w = 0;
  char ch = 0;
  while (!isdigit(ch)) w |= ch == '-', ch = getchar();
  while (isdigit(ch)) X = X * 10 + ch - 48, ch = getchar();
  if (w) return -X;
  return X;
}
bool check(int x) {
  int d = val[x], at = 0, used = 0;
  long long now = 0, sum = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i] <= d) {
      used++;
      at++;
      now += p[i];
      sum += p[i];
      if (now > t) return used - 1 >= x;
      if (at == m) now += sum, sum = 0, at = 0;
      if (now > t) return used >= x;
    }
  }
  return used >= x;
}
signed main() {
  int T = getint();
  while (T--) {
    n = getint(), m = getint(), t = getint();
    for (int i = 1; i <= n; i++) p[i] = val[i] = getint();
    std::sort(val + 1, val + 1 + n);
    int l = 0, r = n, ans = 0;
    val[0] = 1;
    while (l <= r) {
      int mid = l + r >> 1;
      if (check(mid))
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    printf("%d %d\n", ans, val[ans]);
  }
  return 0;
}
