#include <bits/stdc++.h>
using namespace std;
int n, m, a[200010], b[200010], bcnt;
long long t;
int calc(int d) {
  long long sum = 0, cnt = 0, rest = 0;
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    if (a[i] <= d) {
      if (sum + a[i] > t) break;
      sum += a[i];
      cnt++;
      rest += a[i];
      res++;
      if (cnt == m) {
        cnt = 0;
        sum += rest;
        rest = 0;
      }
    }
  }
  return res;
}
int main() {
  int T;
  for (scanf("%d", &T); T--;) {
    scanf("%d%d%lld", &n, &m, &t);
    for (int i = 1; i <= n; ++i) scanf("%d", a + i), b[i] = a[i];
    sort(b + 1, b + n + 1);
    bcnt = unique(b + 1, b + n + 1) - b - 1;
    while (b[bcnt] > t) bcnt--;
    int low = 0, high = bcnt + 1, mid, ans = 0;
    while (low < high - 1) {
      mid = (low + high) >> 1;
      int d = b[mid];
      bool ch = 1;
      long long sum = 0, cnt = 0, rest = 0;
      for (int i = 1; i <= n; ++i) {
        if (a[i] <= d) {
          sum += a[i];
          rest += a[i];
          cnt++;
          if (cnt == m) {
            sum += rest;
            rest = 0;
            cnt = 0;
          }
          if (sum > t) {
            ch = 0;
            break;
          }
        }
      }
      if (ch)
        low = mid;
      else
        high = mid;
    }
    int res1 = -1, res2 = -1;
    if (low > 0) res1 = calc(b[low]);
    if (low + 1 <= bcnt) res2 = calc(b[low + 1]);
    if (res1 == res2 && res1 == -1) {
      puts("0 1");
      continue;
    }
    if (res1 >= res2)
      printf("%d %d\n", res1, b[low]);
    else
      printf("%d %d\n", res2, b[low + 1]);
  }
  return 0;
}
