#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
  long long x = 1 % m;
  a %= m;
  while (b) {
    if ((1 & b)) x = x * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return x;
}
int p[200005];
int ds[200005];
vector<int> possible_d;
int n, m;
long long t;
int solve(int d) {
  int tot_task = 0;
  int batch_task = 0;
  long long batch_time = 0;
  long long T = t;
  for (int i = 1; i <= n; i++) {
    if (batch_task == m) {
      T -= batch_time;
      batch_time = 0;
      batch_task = 0;
    }
    if (T <= 0) break;
    if (p[i] <= d) {
      if (p[i] > T) break;
      T -= p[i];
      tot_task++;
      batch_task++;
      batch_time += p[i];
    }
  }
  return tot_task;
}
void brute() {
  int ans = -1;
  int myd = -1;
  for (int i = 0; i < possible_d.size(); i++) {
    int cur = solve(possible_d[i]);
    if (cur > ans) {
      ans = cur;
      myd = possible_d[i];
    }
  }
  if (ans == 0) {
    ans = 0;
    myd = 1;
  }
  printf("%d %d\n", ans, myd);
}
void trick() {
  int k = possible_d.size();
  int part = sqrt(k);
  vector<int> solve_arr;
  for (int i = 0; i < k; i += part) {
    solve_arr.push_back(solve(possible_d[i]));
  }
  int mx = -1;
  int myd = -1;
  int ind = -1;
  for (int i = 0; i < solve_arr.size(); i++) {
    if (solve_arr[i] > mx) {
      mx = solve_arr[i];
      myd = possible_d[i * part];
      ind = i * part;
    }
  }
  int lim = min(k, ind + 2 * part);
  for (int i = max(ind - 2 * part, 0); i < lim; i++) {
    int cur = solve(possible_d[i]);
    if (cur > mx) {
      mx = cur;
      myd = possible_d[i];
    }
  }
  if (mx == 0) {
    myd = 1;
  }
  printf("%d %d\n", mx, myd);
}
int main() {
  int c;
  scanf("%d", &c);
  while (c--) {
    scanf("%d", &n);
    scanf("%d", &m);
    scanf("%lld", &t);
    for (int i = 1; i <= n; i++) scanf("%d", &p[i]), ds[i] = p[i];
    sort(ds + 1, ds + n + 1);
    possible_d.clear();
    int prev = -1;
    for (int i = 1; i <= n; i++) {
      if (ds[i] != prev) {
        possible_d.push_back(ds[i]);
        prev = ds[i];
      }
    }
    int k = possible_d.size();
    if (k < 1000)
      brute();
    else
      trick();
  }
}
