#include <bits/stdc++.h>
using namespace std;
const long long maxn = 200010;
long long A[maxn];
long long n, m, t;
pair<long long, long long> test(long long x) {
  long long sum = 0, curt = 0, co = 0, coans = 0;
  for (long long i = 0; i < n; i++) {
    if (A[i] > x) continue;
    if (co == m) {
      sum += curt;
      curt = 0;
      co = 0;
    }
    curt += A[i];
    sum += A[i];
    co++;
    if (sum <= t) coans++;
  }
  return pair<long long, long long>((sum <= t), coans);
}
void solve() {
  cin >> n >> m >> t;
  for (long long i = 0; i < n; i++) cin >> A[i];
  vector<long long> v;
  for (long long i = 0; i < n; i++) v.push_back(A[i]);
  sort(v.begin(), v.end());
  long long high = n;
  long long low = 0;
  pair<long long, long long> ans =
      pair<long long, long long>(test(v[0]).first, min(t, v[0]));
  while (high - low > 1) {
    long long mid = (high + low) / 2;
    pair<long long, long long> curv = test(v[mid]);
    if (ans.first < curv.second and v[mid] <= t) {
      ans.first = curv.second;
      ans.second = v[mid];
    }
    if (curv.first)
      low = mid;
    else
      high = mid;
  }
  pair<long long, long long> curv = test(v[low]);
  if (ans.first < curv.second and v[low] <= t) {
    ans.first = curv.second;
    ans.second = v[low];
  }
  cout << ans.first << " " << ans.second << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) solve();
}
