#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int inf = 0x3f3f3f3f;
int n, m;
long long t;
long long p[maxn];
vector<long long> vec;
map<long long, bool> ma;
bool flag;
int check(long long x) {
  int res = 0;
  int cnt = 0;
  long long had = t;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    if (i == n) flag = true;
    if (p[i] > x) continue;
    if (had < p[i]) break;
    had -= p[i];
    sum += p[i];
    ++res;
    if (++cnt == m) {
      had -= sum;
      if (had <= 0) break;
      cnt = 0;
      sum = 0;
    }
  }
  return res;
}
bool judge(long long val) {
  flag = false;
  int temp = check(val);
  return flag;
}
int main() {
  int T;
  scanf("%d", &T);
  for (; T--;) {
    scanf("%d", &n), scanf("%d", &m), scanf("%lld", &t);
    vec.clear();
    ma.clear();
    for (int i = 1; i <= n; ++i) {
      scanf("%lld", &p[i]);
      if (ma.find(p[i]) == ma.end()) {
        ma[p[i]] = true;
        vec.push_back(p[i]);
      }
    }
    vec.push_back(1);
    sort(vec.begin(), vec.end());
    int mx = 0;
    long long id = 1;
    int can = 0, l = 0, r = vec.size() - 1;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (judge(vec[mid]))
        can = mid, l = mid + 1;
      else
        r = mid - 1;
    }
    for (int i = max(0, can - 1); i < min(can + 100, (int)vec.size()); i++) {
      if (vec[i] > t) break;
      int ck = check(vec[i]);
      if (ck >= mx) {
        mx = ck, id = vec[i];
      }
    }
    printf("%d %lld\n", mx, id);
  }
  return 0;
}
