#include <bits/stdc++.h>
using namespace std;
long long n, k, t;
const long long maxn = 2e6 + 55;
long long a[maxn];
long long b[maxn];
long long check(long long val) {
  long long ret = 0, ct = 0, time = 0, all = 0;
  for (long long i = 1; i <= n; i++) {
    if (a[i] > val) continue;
    if (ret + time > t) return all;
    time += a[i];
    if (ret + time > t) return all;
    ct++;
    all++;
    if (ct == k) {
      ct = 0;
      ret += time * 2;
      time = 0;
    }
  }
  return all;
}
void solve() {
  scanf("%lld%lld%lld", &n, &k, &t);
  for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]), b[i] = a[i];
  sort(b + 1, b + 1 + n);
  long long L = 1, R = n, ans = 0;
  while (L <= R) {
    long long mid = (L + R) / 2;
    if (check(b[mid]) < mid)
      R = mid - 1;
    else
      L = mid + 1, ans = mid;
  }
  b[0] = 1;
  cout << ans << ' ' << b[ans] << endl;
}
signed main() {
  long long cas;
  scanf("%lld", &cas);
  while (cas--) solve();
  return 0;
}
