#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e9 + 7;
struct Node {
  int val;
  int id;
} a[N];
struct Tree {
  int sz[N << 2];
  long long T[N << 2];
  void build(int p, int L, int R) {
    sz[p] = 0;
    T[p] = 0;
    if (L == R) return;
    int mid = (L + R) >> 1;
    build(p << 1, L, mid);
    build(p << 1 | 1, mid + 1, R);
  }
  void ins(int p, int L, int R, int pos, int val) {
    sz[p]++;
    T[p] += val;
    if (L == R) return;
    int mid = (L + R) >> 1;
    if (pos <= mid) return ins(p << 1, L, mid, pos, val);
    return ins(p << 1 | 1, mid + 1, R, pos, val);
  }
  long long find(int p, int L, int R, int bound) {
    if (sz[p] <= bound) return T[p];
    if (L == R) return 0;
    int mid = (L + R) >> 1;
    if (bound <= sz[p << 1]) return find(p << 1, L, mid, bound);
    auto tmp = find(p << 1, L, mid, sz[p << 1]);
    auto tmp2 = find(p << 1 | 1, mid + 1, R, bound - sz[p << 1]);
    return tmp + tmp2;
  }
} tr;
int cmp(Node a, Node b) { return a.val < b.val; }
int n, m;
long long t;
int pd(int sz, int bs, long long jq) {
  long long tmp = tr.find(1, 1, n, sz);
  return tmp * bs + jq <= t;
}
int main() {
  int Case;
  scanf("%d", &Case);
  while (Case--) {
    scanf("%d%d%I64d", &n, &m, &t);
    int maxa = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i].val);
      a[i].id = i;
    }
    sort(a + 1, a + n + 1, cmp);
    tr.build(1, 1, n);
    int ans = 0, id = t;
    for (int i = 1; i <= n;) {
      int j = i;
      for (; j <= n; j++) {
        if (a[j].val != a[i].val) break;
        tr.ins(1, 1, n, a[j].id, a[j].val);
      }
      i = j;
      int L = 0, R = (i - 1) / m, tt;
      while (L <= R) {
        int mid = (L + R) >> 1;
        if (pd(mid * m, 2, 0))
          tt = mid, L = mid + 1;
        else
          R = mid - 1;
      }
      long long tmp = tr.find(1, 1, n, tt * m);
      L = tt * m + 1, R = min((tt + 1) * m, i - 1);
      int tt2 = tt * m;
      while (L <= R) {
        int mid = (L + R) >> 1;
        if (pd(mid, 1, tmp))
          tt2 = mid, L = mid + 1;
        else
          R = mid - 1;
      }
      if (tt2 > ans) {
        ans = tt2;
        id = a[i - 1].val;
      }
    }
    printf("%d %d\n", ans, id);
  }
  return 0;
}
