#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long a[N], b[N];
long long T, n, m, t, l, r, ans;
bool check(long long x, long long md) {
  long long tim = 0, now = 0, tot = 0, cnt = 0;
  for (int i = 1; i <= n; i++)
    if (b[i] <= x) {
      tot++, cnt++, tim += b[i], now += b[i];
      if (tot >= md) return tim <= t;
      if (cnt == m) cnt = 0, tim += now, now = 0;
    }
  return tim <= t;
}
int main() {
  scanf("%lld", &T);
  while (T--) {
    scanf("%lld%lld%lld", &n, &m, &t), a[0] = 1;
    for (int i = 1; i <= n; i++) scanf("%lld", &b[i]), a[i] = b[i];
    sort(a + 1, a + n + 1);
    l = 0, r = n;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(a[mid], mid))
        ans = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    printf("%lld %lld\n", ans, a[ans]);
  }
  return 0;
}
