#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
int n, bsz;
long long thave;
int a[MAXN];
pair<int, int> solve() {
  int mn = a[0], mx = a[0];
  for (int i = (1); i < (n); ++i) mn = min(mn, a[i]), mx = max(mx, a[i]);
  int l = mn, r = mx;
  r = (int)min((long long)r, thave);
  l = min(l, r);
  int retval = -1, retcnt = -1;
  while (l <= r) {
    int m = l + (r - l) / 2;
    int cnt = 0;
    long long t = 0, bsum = 0;
    int bcnt = 0;
    bool fits = true;
    for (int i = (0); i < (n); ++i)
      if (a[i] <= m) {
        if (t + a[i] > thave) {
          fits = false;
          break;
        }
        t += a[i], bsum += a[i], ++cnt, ++bcnt;
        if (bcnt < bsz) continue;
        if (t + bsum > thave) {
          fits = false;
          break;
        }
        t += bsum, bsum = 0, bcnt = 0;
      }
    if (cnt > retcnt) retcnt = cnt, retval = m;
    if (fits)
      l = m + 1;
    else
      r = m - 1;
  }
  return make_pair(retcnt, retval);
}
void run() {
  scanf("%d%d%lld", &n, &bsz, &thave);
  for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
  pair<int, int> ans = solve();
  printf("%d %d\n", ans.first, ans.second);
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) run();
  return 0;
}
