#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 200200;
int n, m;
long long t;
long long a[N];
long long b[N];
bool solve(int k) {
  int kk = k - k % m;
  if (kk == k) kk -= m;
  int pos = 0;
  long long T = t;
  for (int i = 0; pos < k; i++) {
    if (a[i] > b[k - 1]) continue;
    T -= a[i];
    if (pos < kk) T -= a[i];
    if (T < 0) return false;
    pos++;
  }
  return true;
}
void solve() {
  scanf("%d%d%lld", &n, &m, &t);
  for (int i = 0; i < n; i++) {
    scanf("%lld", &a[i]);
    b[i] = a[i];
  }
  sort(b, b + n);
  int l = 0, r = n + 1;
  while (r - l > 1) {
    int x = (l + r) / 2;
    if (solve(x))
      l = x;
    else
      r = x;
  }
  printf("%d %lld\n", l, (l == 0 ? 1 : b[l - 1]));
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
