#include <bits/stdc++.h>
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const int N = 2e5 + 5;
long long p[N];
long long n, m, t;
bool check(long long x) {
  long long cnt = 0, las = 0;
  long long T = t;
  for (int i = 1; i <= n; i++) {
    if (p[i] > x) continue;
    if (T < p[i]) return false;
    T -= p[i], cnt++, las += p[i];
    if (cnt % m == 0) T -= las, las = 0;
  }
  return true;
}
long long solve(long long x) {
  long long cnt = 0, las = 0;
  long long T = t;
  for (int i = 1; i <= n; i++) {
    if (p[i] > x) continue;
    if (T < p[i]) break;
    T -= p[i], cnt++, las += p[i];
    if (cnt % m == 0) T -= las, las = 0;
  }
  return cnt;
}
long long upp(long long l, long long r) {
  while (l < r) {
    long long mid = (l + r + 1) >> 1;
    if (check(mid))
      l = mid;
    else
      r = mid - 1;
  }
  return l;
}
int main() {
  int T = read();
  while (T--) {
    n = read(), m = read(), t = read();
    for (int i = 1; i <= n; i++) p[i] = read();
    long long fd = upp(1, t);
    long long l = solve(fd), r = solve(fd + 1);
    if (l >= r)
      printf("%lld %lld\n", l, fd);
    else
      printf("%lld %lld\n", r, fd + 1);
  }
  return 0;
}
