#include <bits/stdc++.h>
using namespace std;
long long n, m, t;
long long p[200002];
long long s[200002];
long long tiv(int tm) {
  long long d = s[tm - 1];
  long long qan = 0;
  long long verj = 0;
  long long sm = 0;
  long long mard = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] <= d) {
      if (sm + p[i] > t) break;
      sm += p[i];
      qan++;
      verj += p[i];
      mard++;
      if (qan == m) {
        qan = 0;
        sm += verj;
        verj = 0;
      }
    }
  }
  if (mard >= tm)
    return d;
  else
    return -1;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    cin >> n >> m >> t;
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      s[i] = p[i];
    }
    sort(s, s + n);
    int l = 0, r = n + 1;
    while (r - l > 1) {
      int tm = (l + r) / 2;
      long long x = tiv(tm);
      if (x == -1) {
        r = tm;
      } else {
        l = tm;
      }
    }
    r = tiv(l);
    if (l == 0) {
      cout << "0 1" << endl;
    } else {
      cout << l << " " << r << endl;
    }
  }
  return 0;
}
