#include <bits/stdc++.h>
using namespace std;
void smain();
int main() {
  ios_base::sync_with_stdio(0);
  smain();
  return 0;
}
long long n, m, T, p[200002];
pair<long long, long long> t[4 * 200002];
void build(long long v, long long l, long long r) {
  t[v] = {0, 0};
  if (l == r) return;
  long long mid = (l + r) / 2;
  build(2 * v, l, mid);
  build(2 * v + 1, mid + 1, r);
}
void upd(long long v, long long l, long long r, long long pos,
         long long delta) {
  if (l == r) {
    t[v].first += delta;
    t[v].second = t[v].first != 0;
    return;
  }
  long long mid = (l + r) / 2;
  if (pos <= mid)
    upd(2 * v, l, mid, pos, delta);
  else
    upd(2 * v + 1, mid + 1, r, pos, delta);
  t[v].first = t[2 * v].first + t[2 * v + 1].first;
  t[v].second = t[2 * v].second + t[2 * v + 1].second;
}
long long get(long long v, long long l, long long r, long long j) {
  if (t[v].second <= j) return t[v].first;
  if (l == r) return 0;
  long long mid = (l + r) / 2;
  long long x = t[2 * v].second;
  if (x >= j) return get(2 * v, l, mid, j);
  return get(2 * v + 1, mid + 1, r, j - x) + t[2 * v].first;
}
void smain() {
  for (cin >> n; cin >> n >> m >> T;) {
    memset(t, 0, sizeof(long long) * n);
    map<long long, vector<long long>> pos;
    for (long long i = 0; i < n; i++) {
      cin >> p[i];
      pos[p[i]].push_back(i);
    }
    build(1, 0, n - 1);
    set<pair<long long, long long>> added;
    long long total = 0, ans = 0, d = 0;
    for (const auto& it : pos) {
      if (it.first > T) break;
      for (const auto& x : it.second) {
        upd(1, 0, n - 1, x, it.first);
        total += it.first;
        added.emplace(x, it.first);
      }
      while (1) {
        long long k = added.size() / m;
        long long j = k * m;
        if (j == (long long)added.size()) j -= m;
        long long s = get(1, 0, n - 1, j);
        if (total - s + 2 * s > T) {
          auto er = *added.rbegin();
          added.erase(er);
          upd(1, 0, n - 1, er.first, -er.second);
          total -= er.second;
        } else {
          break;
        }
      }
      if ((long long)added.size() >= ans) {
        ans = added.size();
        d = it.first;
      }
    }
    cout << ans << ' ' << max(1LL, d) << endl;
  }
}
