#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
  long long ret = 1;
  for (; b; b >>= 1, a = (a * a) % MMM)
    if (b & 1) ret = (ret * a) % MMM;
  return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
  if (a == 0 || b == 0) return a + b;
  return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
int n, m;
long long T, ans;
int a[200001], b[200001];
bool ok(int k) {
  if (k == 0) {
    ans = 1;
    return 1;
  }
  int t = b[k];
  long long c = 0, sum = 0;
  int cnt = 0;
  for (int(i) = (1); (i) <= (n); (i) += (1)) {
    if (a[i] > t) continue;
    cnt++;
    sum += a[i];
    c += a[i];
    if (cnt == k) {
      if (c <= T) {
        ans = t;
        return 1;
      }
      return 0;
    }
    if (cnt % m == 0) {
      c += sum;
      sum = 0;
    }
  }
  return 0;
}
void solve() {
  scanf("%d%d%lld", &n, &m, &T);
  for (int(i) = (1); (i) <= (n); (i) += (1)) scanf("%d", a + i), b[i] = a[i];
  sort(b + 1, b + n + 1);
  int l = 1, r = n;
  while (l <= r) {
    int k = (l + r) >> 1;
    if (ok(k))
      l = k + 1;
    else
      r = k - 1;
  }
  ok(r);
  printf("%d %lld\n", r, ans);
}
int main() {
  int tc;
  scanf("%d", &tc);
  while (tc--) solve();
}
