#include <bits/stdc++.h>
using namespace std;
long long p[200010];
int idx[200010], n, m;
long long T;
long long check(int k) {
  if (k == 0) return T;
  if (k == n + 1) return -1;
  long long d = min(p[idx[k - 1]], T);
  long long t = 0, res = 0, cnt = 0;
  for (int i = 0; i < n; i++) {
    if (p[i] > d) continue;
    if (cnt % m == 0) {
      t += 2 * res;
      res = 0;
    }
    if (t + res + p[i] <= T) {
      res += p[i];
      cnt += 1;
    } else {
      break;
    }
  }
  if (cnt >= k) return d;
  return -1;
}
bool cmp(int x, int y) { return p[x] < p[y]; }
int main() {
  int C, L, R, mid;
  long long ans;
  scanf("%d", &C);
  while (C--) {
    scanf("%d %d %I64d", &n, &m, &T);
    for (int i = 0; i < n; i++) {
      scanf("%I64d", &p[i]);
    }
    for (int i = 0; i < n; i++) {
      idx[i] = i;
    }
    sort(idx, idx + n, cmp);
    L = 0;
    R = n + 1;
    ans = min(p[0], T);
    while (L < R) {
      mid = (L + R) / 2;
      ans = check(mid);
      if (ans == -1)
        R = mid;
      else
        L = mid + 1;
    }
    if (L >= 1) {
      L -= 1;
    }
    if (L >= 1) {
      ans = min(p[idx[L - 1]], T);
    }
    printf("%d %I64d\n", L, ans);
  }
  return 0;
}
