#include <bits/stdc++.h>
using namespace std;
int k;
long long t;
vector<int> p;
bool f(int x) {
  int cnt = 0, last = -1;
  long long sum = 0, time = 0;
  for (int i = 0; i < p.size(); ++i)
    if (p[i] <= x) last = i;
  for (int i = 0; i <= last; ++i) {
    if (cnt == k) {
      time += sum;
      cnt = 0;
      sum = 0;
    }
    if (p[i] <= x) {
      time += p[i];
      ++cnt;
      sum += p[i];
    }
  }
  return time <= t;
}
pair<int, int> bs(int l, int r) {
  while (r - l > 1) {
    int m = (l + r) / 2;
    if (f(m))
      l = m;
    else
      r = m;
  }
  return make_pair(l, r);
}
int calc(int x, long long t) {
  int res = 0, cnt = 0;
  long long sum = 0, time = 0;
  for (int i = 0; i < p.size(); ++i) {
    if (cnt == k) {
      time += sum;
      cnt = 0;
      sum = 0;
    }
    if (p[i] <= x) {
      if (time + p[i] > t) break;
      time += p[i];
      ++cnt;
      sum += p[i];
      ++res;
    }
  }
  return res;
}
void solve() {
  int n;
  cin >> n >> k >> t;
  p.resize(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  pair<int, int> ans = bs(1, min(200001ll, t));
  int a = calc(ans.first, t);
  int b = calc(ans.second, t);
  if (a >= b)
    cout << a << ' ' << ans.first << endl;
  else
    cout << b << ' ' << ans.second << endl;
}
int main() {
  int test;
  cin >> test;
  for (int i = 0; i < test; ++i) solve();
  return 0;
}
