#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int N = 2e5 + 5;
long long n, m, x, t, T;
map<long long, vector<long long> > g;
pair<long long, long long> ans;
long long ft[2][N];
void add(long long id, long long pos, long long val) {
  for (; pos <= n; pos += (pos & -pos)) ft[id][pos] += val;
}
long long query(long long id, long long pos) {
  long long ans = 0;
  for (; pos > 0; pos -= (pos & -pos)) ans += ft[id][pos];
  return ans;
}
long long getTime(long long cnt) {
  long long tot = query(0, cnt);
  long long task_cnt = query(1, cnt);
  long long rest_cnt = m * ((task_cnt - 1) / m);
  long long lo = 0, hi = cnt;
  while (lo < hi) {
    long long mid = (lo + hi) >> 1;
    if (query(1, mid) < rest_cnt)
      lo = mid + 1;
    else
      hi = mid;
  }
  return tot + query(0, lo);
}
pair<long long, long long> solve(long long thisd = t) {
  long long lo = 0, hi = n;
  while (lo < hi) {
    long long mid = (lo + hi + 1) >> 1;
    if (getTime(mid) <= t)
      lo = mid;
    else
      hi = mid - 1;
  }
  return {query(1, lo), thisd};
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> n >> m >> t;
    g.clear();
    for (long long i = 0; i <= n; i++) ft[0][i] = ft[1][i] = 0;
    for (long long i = 1; i <= n; i++) {
      cin >> x;
      if (x > t) continue;
      add(0, i, x);
      add(1, i, 1);
      g[x].push_back(i);
    }
    ans = solve();
    for (auto it = g.rbegin(); it != g.rend(); it++) {
      vector<long long> v = it->second;
      for (long long u : v) {
        add(0, u, -it->first);
        add(1, u, -1);
      }
      auto cur = solve(it->first - 1);
      if (cur.first > ans.first) ans = cur;
    }
    cout << ans.first << " " << ans.second << "\n";
  }
}
