#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
pair<int, long long> operator+(const pair<int, long long> &A,
                               const pair<int, long long> &B) {
  return {A.first + B.first, A.second + B.second};
}
pair<int, long long> operator-(const pair<int, long long> &A,
                               const pair<int, long long> &B) {
  return {A.first - B.first, A.second - B.second};
}
struct FenwickTree {
  pair<int, long long> fw[N];
  void Update(int i, pair<int, long long> v) {
    for (i; i < N; i += i & -i) fw[i] = fw[i] + v;
  }
  pair<int, long long> Query(int i) {
    pair<int, long long> ans = {0, 0};
    for (i; i > 0; i -= i & -i) ans = ans + fw[i];
    return ans;
  }
  pair<int, long long> Query(int l, int r) {
    if (l > r) return {0, 0};
    return Query(r) - Query(l - 1);
  }
} active_task;
int n, m;
int a[N], b[N];
long long t;
vector<int> val[N];
int find_index(int x, int r) {
  int l = 1, f = 0;
  while (l <= r) {
    int m = (l + r) >> 1;
    pair<int, long long> ret = active_task.Query(m);
    if (ret.first <= x) {
      f = m;
      l = m + 1;
    } else
      r = m - 1;
  }
  return f;
}
void Solve() {
  cin >> n >> m >> t;
  int number = m;
  pair<int, long long> ans = {t, 0};
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    b[i] = a[i];
  }
  sort(b + 1, b + n + 1);
  int bSize = unique(b + 1, b + n + 1) - (b + 1);
  for (int i = 1; i <= n; ++i) val[a[i]].push_back(i);
  for (int i = 1; i <= bSize; ++i) {
    int value = b[i];
    for (int idx : val[value]) {
      active_task.Update(idx, {1, a[idx]});
    }
    int l = 1, r = n, f = -1;
    while (l <= r) {
      int m = (l + r) >> 1;
      pair<int, long long> ret1 = active_task.Query(m);
      int idx = find_index((ret1.first - 1) / number * number, m);
      pair<int, long long> ret2 = active_task.Query(idx);
      long long sum = ret2.second * 2LL + active_task.Query(idx + 1, m).second;
      if (sum <= t) {
        l = m + 1;
        f = m;
      } else
        r = m - 1;
    }
    if (f != -1) {
      pair<int, long long> ret = active_task.Query(f);
      if (ret.first > ans.second) ans = {value, ret.first};
    }
  }
  cout << ans.second << " " << ans.first << '\n';
  for (int i = 1; i <= n; ++i)
    active_task.Update(i, {-1, -a[i]}), val[a[i]].clear();
}
int main() {
  int TC;
  cin >> TC;
  while (TC--) {
    Solve();
  }
}
