#include <bits/stdc++.h>
using namespace std;
long long s[1 << 20];
long long s1[1 << 20];
int Maxsize;
void add(long long *ss, int first, long long add) {
  for (int i = first; i < Maxsize; i += i & -i) {
    ss[i] += add;
  }
}
long long query(long long *ss, int first) {
  long long res = 0;
  for (int i = first; i > 0; i -= i & -i) {
    res += ss[i];
  }
  return res;
}
int query2(long long *ss, int need) {
  int res = 0;
  long long sum = 0;
  for (int i = Maxsize >> 1; i > 0; i >>= 1) {
    if (sum + ss[res + i] <= need) {
      sum += ss[res + i];
      res += i;
    }
  }
  return res;
}
pair<long long, long long> p[200005];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    long long n, m, t;
    scanf("%lld %lld %lld", &n, &m, &t);
    for (int i = 1;; i <<= 1) {
      if (i > n) {
        Maxsize = i;
        break;
      }
    }
    fill(s, s + Maxsize + 1, 0);
    fill(s1, s1 + Maxsize + 1, 0);
    for (int i = 1; i <= n; i++) {
      int a;
      scanf("%d", &a);
      p[i] = make_pair(a, i);
    }
    p[0] = make_pair(0, 0);
    p[n + 1] = make_pair(0, 0);
    sort(p + 1, p + n + 1);
    int ans = -1, ansd;
    for (int i = 1; i <= n; i++) {
      add(s1, p[i].second, 1);
      add(s, p[i].second, p[i].first);
      if (p[i].first != p[i + 1].first) {
        int Max = i + 1, Min = 0;
        while (Max > Min + 1) {
          int mid = (Max + Min) / 2;
          int sub;
          if (mid % m == 0)
            sub = m;
          else
            sub = mid % m;
          int p1 = query2(s1, mid), p2 = query2(s1, mid - sub);
          long long tot = query(s, p1) + query(s, p2);
          if (tot > t) {
            Max = mid;
          } else {
            Min = mid;
          }
        }
        if (ans < Min) {
          ans = Min;
          ansd = p[i].first;
        }
      }
    }
    if (ansd > t) ansd = t;
    printf("%d %d\n", ans, ansd);
  }
}
