#include <bits/stdc++.h>
using namespace std;
long long input() {
  long long x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
long long n, m, Ti;
long long P[(int)2e5 + 7], p[(int)2e5 + 7];
bool check(long long d, long long Mid) {
  long long ans = 0, cnt = 0, _t = 0;
  for (int i = 1; i <= n; i++) {
    if (P[i] > d) continue;
    cnt++;
    _t += P[i];
    ans += P[i];
    if (cnt == Mid) return ans <= Ti;
    if (cnt && cnt % m == 0) ans += _t, _t = 0;
    if (ans > Ti) return 0;
  }
  return 0;
}
void Solve() {
  n = input(), m = input(), Ti = input();
  int l = 1, r = n, ans = 0;
  for (int i = 1; i <= n; i++) P[i] = input(), p[i] = P[i];
  sort(p + 1, p + 1 + n);
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(p[mid], mid))
      l = mid + 1, ans = mid;
    else
      r = mid - 1;
  }
  if (ans == 0)
    printf("0 1\n");
  else
    printf("%d %lld\n", ans, p[ans]);
  return;
}
int T;
int main() {
  T = input();
  while (T--) {
    Solve();
  }
}
