#include <bits/stdc++.h>
using namespace std;
vector<long long> A;
long long k, T, n;
bool check(long long d) {
  long long cnt = 0;
  long long sum = 0;
  long long time = 0;
  for (long long i = 0; i < n; i++) {
    if (A[i] <= d) {
      if (cnt == k) {
        time += sum;
        sum = 0;
        cnt = 0;
      }
      if (time + A[i] > T) {
        return false;
      }
      sum += A[i];
      time += A[i];
      cnt++;
    }
  }
  return true;
}
long long check2(long long d) {
  long long C = 0;
  long long cnt = 0;
  long long sum = 0;
  long long time = 0;
  for (long long i = 0; i < n; i++) {
    if (A[i] <= d) {
      if (cnt == k) {
        time += sum;
        sum = 0;
        cnt = 0;
      }
      if (time + A[i] > T) {
        return C;
      }
      time += A[i];
      sum += A[i];
      cnt++;
      C++;
    }
  }
  return C;
}
int main() {
  ios_base::sync_with_stdio(false);
  long long q;
  cin >> q;
  for (long long asd = 0; asd < q; asd++) {
    cin >> n >> k >> T;
    A.resize(n);
    long long maxx = 0;
    for (long long i = 0; i < n; i++) {
      cin >> A[i];
      maxx = max(maxx, A[i]);
    }
    long long l = 0, r = maxx + 1;
    while (l < r) {
      long long mi = (l + r) / 2;
      if (check(mi))
        l = mi + 1;
      else
        r = mi;
    }
    pair<long long, long long> H1, H2;
    H1 = {check2(min(max(1ll, l - 1), T)), min(max(1ll, l - 1), T)};
    H2 = {check2(max(1ll, min(min(l, maxx), T))),
          max(1ll, min(min(l, maxx), T))};
    cout << max(H1, H2).first << " " << max(H1, H2).second << '\n';
  }
  return 0;
}
