#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 100;
long long a[N], b[N];
long long n, m, t;
bool check(long long x, long long d) {
  long long s = 0, sum = 0, cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] > d) continue;
    s += b[i];
    sum += b[i];
    cnt++;
    if (cnt == x) {
      if (s <= t)
        return true;
      else
        return false;
    }
    if (cnt % m == 0) s += sum, sum = 0;
    if (s > t) return false;
  }
  return false;
}
int main() {
  int c;
  scanf("%d", &c);
  while (c--) {
    scanf("%lld%lld%lld", &n, &m, &t);
    for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]), b[i] = a[i];
    long long ans = 0;
    int l = 1, r = n;
    sort(a + 1, a + 1 + n);
    while (l <= r) {
      int mid = l + r >> 1;
      if (check(mid, a[mid]))
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    printf("%lld %lld\n", ans, (ans > 0 ? a[ans] : 1));
  }
  return 0;
}
