#include <bits/stdc++.h>
using namespace std;
int n;
long long m, t;
const int N = 200002;
long long a[N];
bool full(int d, int& cnt) {
  cnt = 0;
  int sofar = 0;
  long long cum = 0;
  long long time = 0;
  bool done = false;
  for (int i = 0; i < n; i++) {
    int curr = a[i];
    if (curr <= d) {
      if (time + curr > t) {
        done = true;
        break;
      }
      cnt++;
      sofar++;
      cum += curr;
      time += curr;
      if (sofar == m) {
        sofar = 0;
        time += cum;
        cum = 0;
      }
    }
  }
  return done;
}
void solve() {
  cin >> n >> m >> t;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int l = 0;
  int r = 1e7;
  while (l + 1 != r) {
    int mid = (l + r) / 2;
    int x;
    if (full(mid, x)) {
      r = mid;
    } else {
      l = mid;
    }
  }
  int cntl, cntr;
  full(l, cntl);
  full(r, cntr);
  if (cntl >= cntr) {
    if (l < 1) {
      l = 1;
    }
    if (l > t) {
      l = t;
    }
    cout << cntl << " " << l << "\n";
  } else {
    if (r < 1) {
      r = 1;
    }
    if (r > t) {
      r = t;
    }
    cout << cntr << " " << r << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  for (int t = 0; t < T; t++) {
    solve();
  }
  return 0;
}
