#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5 + 10;
long long a[MAX_N], n, m, t;
vector<int> vec;
long long get(long long d) {
  d = vec[d];
  long long cnt = 0, mm = 0;
  long long T = 0, tmpT = 0;
  for (int i = 0; i < n; i++) {
    if (a[i] > d) {
      continue;
    }
    tmpT += a[i];
    T += a[i];
    cnt++;
    mm++;
    if (T > t) {
      return cnt - 1;
    } else if (mm == m) {
      mm = 0;
      T += tmpT;
      tmpT = 0;
    }
  }
  return cnt;
}
int main() {
  int _;
  for (scanf("%d", &_); _; _--) {
    vec.clear();
    scanf("%lld%lld%lld", &n, &m, &t);
    for (int i = 0; i < n; i++) {
      scanf("%lld", a + i);
      if (a[i] <= t) vec.push_back(a[i]);
    }
    vec.push_back(t);
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    int siz = vec.size();
    long long l = 0, r = siz - 1;
    while (l < r - 1) {
      long long mid = (l + r) / 2, midd = (mid + r) / 2;
      if (get(mid) < get(midd)) {
        l = mid + 1;
      } else {
        r = midd;
      }
    }
    long long ans1, ans2;
    if (get(r) >= get(l))
      ans2 = vec[r], ans1 = get(r);
    else
      ans2 = vec[l], ans1 = get(l);
    if (r + 1 != siz) {
      if (get(r + 1) > get(r)) {
        ans2 = vec[r + 1], ans1 = get(r + 1);
      }
    }
    printf("%lld %lld\n", ans1, ans2);
  }
  return 0;
}
