#include <bits/stdc++.h>
using namespace std;
struct fenwick_tree {
  int n;
  vector<long long> ft;
  fenwick_tree(int n) : n(n), ft(n + 1) {}
  void update(int p, long long v) {
    for (; p <= n; p += p & -p) ft[p] += v;
  }
  long long query(int p) {
    long long ans = 0;
    for (; p > 0; p -= p & -p) ans += ft[p];
    return ans;
  }
  long long query(int a, int b) { return query(b) - query(a - 1); }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int c;
  cin >> c;
  while (c--) {
    long long n, m, t;
    cin >> n >> m >> t;
    vector<pair<long long, long long> > ord(n);
    for (long long i = 0, p; i < n; ++i) cin >> p, ord[i] = {p, i + 1};
    sort(ord.begin(), ord.end());
    pair<long long, long long> best = {0, 1};
    fenwick_tree sel(n + 10), cnt(n + 10);
    function<int(long long)> g = [&](long long x) {
      int l = 0, r = n;
      if (x == 0) return l;
      while (l + 1 < r) {
        int mid = (l + r) >> 1;
        if (cnt.query(mid) >= x)
          r = mid;
        else
          l = mid;
      }
      return r;
    };
    function<bool(int)> f = [&](int mid) {
      long long tot = sel.query(mid);
      long long idx = cnt.query(mid);
      if (idx >= m) {
        tot += sel.query(g(idx / m * m));
        if (idx % m == 0) tot -= sel.query(g(idx - m + 1), g(idx));
      }
      return tot <= t;
    };
    ord.push_back({ord.back().first + 1, n});
    for (int i = 0; i < n; ++i) {
      if (ord[i].first > t) break;
      sel.update(ord[i].second, ord[i].first);
      cnt.update(ord[i].second, +1);
      if (ord[i].first != ord[i + 1].first) {
        int l = 0, r = n;
        if (f(r)) l = r;
        while (l + 1 < r) {
          int mid = (l + r) >> 1;
          if (f(mid))
            l = mid;
          else
            r = mid;
        }
        best =
            max(best, pair<long long, long long>(cnt.query(l), ord[i].first));
      }
    }
    cout << best.first << " " << best.second << '\n';
  }
  return 0;
}
