#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int ntest;
int n, m;
long long t;
int p[maxn];
vector<int> vals;
vector<vector<int>> id;
struct fenwick {
  int n;
  int cnt[maxn];
  long long sum[maxn];
  void init(int x) {
    n = x;
    fill(cnt + 1, cnt + n + 1, 0);
    fill(sum + 1, sum + n + 1, 0);
  }
  void update(int x, int k) {
    for (; x <= n; x += x & -x) {
      ++cnt[x];
      sum[x] += k;
    }
  }
  int get_cnt(int x) {
    int res = 0;
    for (; x > 0; x -= x & -x) res += cnt[x];
    return res;
  }
  long long get_sum(int x) {
    long long res = 0;
    for (; x > 0; x -= x & -x) res += sum[x];
    return res;
  }
  int get_cnt(int l, int r) { return get_cnt(r) - get_cnt(l - 1); }
  long long get_sum(int l, int r) { return get_sum(r) - get_sum(l - 1); }
} tree;
void read_input() {
  cin >> n >> m >> t;
  for (int i = 1; i <= n; ++i) cin >> p[i];
}
void init() {
  vals.clear();
  for (int i = 1; i <= n; ++i) vals.push_back(p[i]);
  sort(vals.begin(), vals.end());
  vals.erase(unique(vals.begin(), vals.end()), vals.end());
  id.resize((int)vals.size());
  for (int i = 0; i < (int)vals.size(); ++i) id.clear();
  for (int i = 1; i <= n; ++i) {
    int pos = lower_bound(vals.begin(), vals.end(), p[i]) - vals.begin();
    id[pos].push_back(i);
  }
}
long long calc(int x) {
  int num = tree.get_cnt(x);
  int r = num % m;
  if (r == 0) r = m;
  int low = 1, high = x;
  while (low <= high) {
    int mid = (low + high) / 2;
    if (tree.get_cnt(mid) <= num - r)
      low = mid + 1;
    else
      high = mid - 1;
  }
  return tree.get_sum(x) + tree.get_sum(high);
}
void solve() {
  tree.init(n);
  int mx = 0, d = 1;
  for (int i = 0; i < (int)vals.size(); ++i) {
    for (auto& x : id[i]) tree.update(x, vals[i]);
    int low = 1, high = n;
    while (low <= high) {
      int mid = (low + high) / 2;
      if (calc(mid) <= t)
        low = mid + 1;
      else
        high = mid - 1;
    }
    int nval = tree.get_cnt(high);
    if (mx < nval) {
      mx = nval;
      d = vals[i];
    }
  }
  cout << mx << ' ' << d << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> ntest;
  while (ntest--) {
    read_input();
    init();
    solve();
  }
}
