#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
long long n, m, t, P[N];
pair<long long, long long> A[N];
long long f[N], idxs[N];
void upd(long long *f, int i, long long v) {
  i++;
  for (; i < n + 1; i += i & -i) f[i] += v;
}
long long sum(long long *f, int i) {
  long long res = 0;
  i++;
  for (; i; i -= i & -i) res += f[i];
  return res;
}
int get(int i) {
  int lw = 0, hg = n - 1, ans = n, mid;
  while (hg >= lw) {
    mid = (lw + hg) / 2;
    if (sum(idxs, mid) >= i) {
      ans = min(ans, mid);
      hg = mid - 1;
    } else {
      lw = mid + 1;
    }
  }
  return ans;
}
bool can(long long v) {
  int i = (v / m) * m;
  if (i == 0) return sum(f, get(v)) <= t;
  if (i == v) {
    int c = ((i - 1) / m) * m;
    if (c == 0) return sum(f, get(v)) <= t;
    return sum(f, get(v)) + sum(f, get(c)) <= t;
  }
  return sum(f, get(v)) + sum(f, get(i)) <= t;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> m >> t;
    for (int x = 0, ThxDem = n; x < ThxDem; ++x) cin >> P[x], A[x] = {P[x], x};
    sort(A, A + n);
    pair<long long, long long> ans = {0, 1};
    for (int x = 0, ThxDem = n; x < ThxDem; ++x) {
      int xs = x;
      while (x + 1 < n && A[x + 1].first == A[xs].first) x++;
      for (int i = xs, ThxDem = x + 1; i < ThxDem; ++i) {
        upd(f, A[i].second, A[i].first);
        upd(idxs, A[i].second, 1);
      }
      int lw = 0, hg = x + 1, mid, aa = 0;
      while (hg >= lw) {
        mid = (hg + lw) / 2;
        if (can(mid)) {
          aa = max(aa, mid);
          lw = mid + 1;
        } else
          hg = mid - 1;
      }
      ans = min(ans, {-aa, A[xs].first});
    }
    for (int x = 0, ThxDem = n + 2; x < ThxDem; ++x) f[x] = 0, idxs[x] = 0;
    cout << -ans.first << " " << ans.second << "\n";
  }
}
