#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e16;
const double pi = 3.1415926535898;
bool debug = 0;
const int MX = 1e6 + 100;
const int MAXN = 4e5 + 500;
const int LOG = 20;
const long long mod = 998244353;
int n, m;
long long t;
int a[MAXN];
int fun(int val) {
  int ans = 0;
  long long cur = 0;
  long long last = 0;
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] > val) continue;
    if (cur + a[i] > t) break;
    ans++;
    cur += a[i];
    last += a[i];
    cnt++;
    if (cnt == m) {
      cur += last;
      last = 0;
      cnt = 0;
    }
  }
  return ans;
}
void solve() {
  cin >> n;
  cin >> m;
  cin >> t;
  vector<int> all;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    if (a[i] <= t) all.push_back(a[i]);
  }
  sort(all.begin(), all.end());
  all.resize(unique(all.begin(), all.end()) - all.begin());
  int l = 0, r = all.size() - 1;
  int ans = 0;
  int pos = 1;
  while (r - l > 100) {
    int m1 = l + (r - l) / 3;
    int m2 = r - (r - l) / 3;
    int res1 = fun(all[m1]);
    int res2 = fun(all[m2]);
    if (res1 < res2) {
      l = m1;
    } else {
      r = m2;
    }
    if (res1 > ans) {
      ans = res1;
      pos = all[m1];
    }
    if (res2 > ans) {
      ans = res2;
      pos = all[m2];
    }
  }
  for (int i = l; i <= r; ++i) {
    int x = fun(all[i]);
    if (debug) cout << i << " " << all[i] << " - " << x << endl;
    if (x > ans) {
      ans = x;
      pos = all[i];
    }
  }
  if (debug) cout << " ANS " << endl;
  cout << ans << " " << pos << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.precision(20);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
