#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
long long a[N], b[N];
int n, m;
long long t;
int chk(int d) {
  int tot = 0, cnt = 0;
  long long prv = 0, timer = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] <= d) {
      timer += a[i];
      if (timer > t) return 1;
      cnt++;
      tot++;
      if (cnt == m) {
        cnt = 0;
        timer += timer - prv;
        prv = timer;
      }
    }
  }
  if (timer > t) return 1;
  return 0;
}
int getcnt(int d) {
  int tot = 0, cnt = 0;
  long long prv = 0, timer = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] <= d) {
      timer += a[i];
      if (timer > t) break;
      cnt++;
      tot++;
      if (cnt == m) {
        cnt = 0;
        timer += timer - prv;
        prv = timer;
      }
    }
  }
  return tot;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  while (tt--) {
    cin >> n >> m >> t;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    sort(b + 1, b + n + 1);
    int lod = 0, hid = n, ansd = n;
    while (lod <= hid) {
      long long mid = (lod + hid) / 2;
      int ret = chk(b[mid]);
      if (ret == 1) {
        ansd = mid;
        hid = mid - 1;
      } else {
        lod = mid + 1;
      }
    }
    int t1 = getcnt(b[ansd - 1]);
    int t2 = getcnt(b[ansd]);
    if (t1 > t2) {
      cout << t1 << " " << min(t, b[ansd - 1]) << "\n";
    } else {
      cout << t2 << " " << min(t, b[ansd]) << "\n";
    }
  }
  return 0;
}
