#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 200011;
long long a[MAXN], v[MAXN];
int main() {
  long long ii, tt, i, j, k, m, n, d, md, maxt, mx, t, ct, oct, res1, res2, sum,
      osum, L, R, M;
  cin >> tt;
  for (ii = 0; ii < tt; ii++) {
    cin >> n >> m >> maxt;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      v[i] = a[i];
    }
    sort(v, v + n);
    mx = 0;
    md = 1;
    L = 0;
    R = n;
    while (L + 1 < R) {
      M = (L + R) / 2;
      d = v[M];
      osum = 0;
      sum = 0;
      oct = 0;
      ct = 0;
      t = 0;
      for (i = 0; i < n; i++) {
        if (a[i] <= d) {
          sum += a[i];
          osum += a[i];
          ct++;
          if (osum > maxt) break;
          oct++;
          if (ct == m) {
            ct = 0;
            osum += sum;
            sum = 0;
            if (osum > maxt) break;
          }
        }
      }
      if (oct >= mx) {
        mx = oct;
        md = d;
      }
      if (osum <= maxt) {
        L = M;
      } else {
        R = M;
      }
    }
    d = v[L];
    osum = 0;
    sum = 0;
    oct = 0;
    ct = 0;
    t = 0;
    for (i = 0; i < n; i++) {
      if (a[i] <= d) {
        sum += a[i];
        osum += a[i];
        ct++;
        if (osum > maxt) break;
        oct++;
        if (ct == m) {
          ct = 0;
          osum += sum;
          sum = 0;
          if (osum > maxt) break;
        }
      }
    }
    if (oct >= mx) {
      mx = oct;
      md = d;
    }
    md = min(md, maxt);
    cout << mx << ' ' << md << endl;
  }
  return 0;
}
