#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
long long c, n, m, t, p[N];
long long sum[N * 4];
int cnt[N * 4];
void update(int pos, int id = 1, int l = 0, int r = n) {
  if (l + 1 == r) {
    sum[id] += p[l];
    cnt[id]++;
    return;
  }
  int m = (l + r) >> 1;
  if (pos < m)
    update(pos, id * 2, l, m);
  else
    update(pos, id * 2 + 1, m, r);
  cnt[id] = cnt[id * 2] + cnt[id * 2 + 1];
  sum[id] = sum[id * 2] + sum[id * 2 + 1];
}
long long get(int skip, int c, int id = 1, int l = 0, int r = n) {
  if (skip == 0 && cnt[id] == c) return sum[id];
  int m = (l + r) >> 1;
  if (cnt[id * 2] >= skip + c)
    return get(skip, c, id * 2, l, m);
  else if (cnt[id * 2] <= skip)
    return get(skip - cnt[id * 2], c, id * 2 + 1, m, r);
  long long ans = get(skip, cnt[id * 2] - skip, id * 2, l, m);
  return ans + get(0, c - cnt[id * 2] + skip, id * 2 + 1, m, r);
}
bool ok(int cnt) {
  int cntlft = cnt / m;
  int cntrit = cnt % m;
  if (!cntrit) cntlft--, cntrit = m;
  cntlft *= m;
  long long lft = get(0, cntlft) * 2;
  long long rit = get(cntlft, cntrit);
  return lft + rit <= t;
}
void clear(int id = 1, int l = 0, int r = n) {
  sum[id] = 0;
  cnt[id] = 0;
  if (l + 1 == r) return;
  int m = (l + r) >> 1;
  clear(id * 2, l, m);
  clear(id * 2 + 1, m, r);
}
int main() {
  cin >> c;
  while (c--) {
    cin >> n >> m >> t;
    map<long long, vector<int>> mp;
    for (int i = 0; i < n; ++i) {
      scanf("%lld", p + i);
      mp[p[i]].push_back(i);
    }
    long long ans = 0, d = 1;
    int added = 0;
    for (auto &it : mp) {
      vector<int> &pos = it.second;
      for (int i : pos) update(i), added++;
      int l = 0, r = added, m;
      while (l < r) {
        m = (l + r + 1) / 2;
        if (ok(m))
          l = m;
        else
          r = m - 1;
      }
      if (l > ans) ans = l, d = it.first;
    }
    printf("%lld %lld\n", ans, d);
    clear();
  }
}
