#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 15;
long long ps[N];
long long cc[N];
void update(long long *pen, int ind, int add, int lim) {
  while (ind <= lim) {
    pen[ind] += add;
    ind += ind & (-ind);
  }
}
long long query(long long *pen, int ind) {
  long long ret = 0;
  while (ind > 0) {
    ret += pen[ind];
    ind = ind & (ind - 1);
  }
  return ret;
}
int p[N];
long long getTime(int ind, int m, int n) {
  int x = query(cc, ind);
  long long ret = query(ps, ind);
  x = max(0, ((x - 1) / m) * m);
  int bit = 0;
  long long sum = 0;
  for (int i = 19; i >= 0; --i) {
    int tmpBit = bit + (1 << i);
    if (tmpBit > n) continue;
    sum += cc[tmpBit];
    if (sum <= x) {
      bit = tmpBit;
    } else {
      sum -= cc[tmpBit];
    }
  }
  ret += query(ps, bit);
  return ret;
}
void solve() {
  int n, m;
  long long t;
  cin >> n >> m >> t;
  vector<pair<int, int> > in;
  for (int i = 1; i <= n; ++i) {
    ps[i] = cc[i] = 0;
    cin >> p[i];
    in.push_back(make_pair(p[i], i));
  }
  sort(in.begin(), in.end());
  int ret = 0;
  int lim = 1;
  for (int i = 0; i < in.size();) {
    int j;
    for (j = i; j < in.size(); ++j) {
      if (in[j].first != in[i].first) {
        break;
      }
      int ind = in[j].second;
      int val = in[j].first;
      update(cc, ind, 1, n);
      update(ps, ind, val, n);
    }
    int l = 0, r = n, mid;
    while (l < r) {
      mid = (l + r + 1) / 2;
      if (getTime(mid, m, n) <= t) {
        l = mid;
      } else {
        r = mid - 1;
      }
    }
    if (ret < (int)query(cc, l)) {
      ret = query(cc, l);
      lim = in[i].first;
    }
    i = j;
  }
  cout << ret << " " << lim << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int c;
  cin >> c;
  while (c--) {
    solve();
  }
}
