#include <bits/stdc++.h>
using namespace std;
void setmin(int &x, int y) { x = min(x, y); }
void setmax(int &x, int y) { x = max(x, y); }
void setmin(long long &x, long long y) { x = min(x, y); }
void setmax(long long &x, long long y) { x = max(x, y); }
const long long llinf = 1e18 + 100;
const int maxn = 2e5 + 100, maxw = (1 << 19) + 10, inf = 1e9 + 100,
          mod = 1e9 + 993;
struct seg_tree {
  vector<int> q;
  vector<long long> p;
  void build(int n) {
    q.resize(4 * n);
    p.resize(4 * n);
  }
  int get(int v, int l, int r, int id) {
    if (id == 0) return -1;
    if (l == r) return l;
    int m = (l + r) / 2;
    if (q[2 * v] >= id) return get(2 * v, l, m, id);
    return get(2 * v + 1, m + 1, r, id - q[2 * v]);
  }
  long long get(int v, int tl, int tr, int l, int r) {
    if (l > r) return 0;
    if (tl == l && tr == r) return p[v];
    int m = (tl + tr) / 2;
    return get(2 * v, tl, m, l, min(r, m)) +
           get(2 * v + 1, m + 1, tr, max(l, m + 1), r);
  }
  void update(int v, int l, int r, int id, int val) {
    if (l == r) {
      q[v] = (val > 0);
      p[v] = val;
      return;
    }
    int m = (l + r) / 2;
    if (id <= m)
      update(2 * v, l, m, id, val);
    else
      update(2 * v + 1, m + 1, r, id, val);
    q[v] = q[2 * v] + q[2 * v + 1];
    p[v] = p[2 * v] + p[2 * v + 1];
  }
  int solve(int n, int k, long long t) {
    while (1) {
      int cnt = q[1];
      if (cnt == 0) break;
      int r = cnt % k;
      if (r == 0) r = k;
      int pos = get(1, 0, n - 1, cnt - r);
      long long val = get(1, 0, n - 1, 0, pos);
      if (p[1] + val <= t) break;
      pos = get(1, 0, n - 1, cnt);
      update(1, 0, n - 1, pos, 0);
    }
    return q[1];
  }
};
pair<int, int> mas[maxn];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tst;
  cin >> tst;
  while (tst--) {
    int n, m;
    long long t;
    cin >> n >> m >> t;
    for (int i = 0; i < n; i++) cin >> mas[i].first, mas[i].second = i;
    sort(mas, mas + n);
    int ans = 0, anst = 1;
    seg_tree q;
    q.build(n);
    for (int i = 0; i < n && mas[i].first <= t; i++) {
      q.update(1, 0, n - 1, mas[i].second, mas[i].first);
      if (i == n - 1 || mas[i].first != mas[i + 1].first) {
        int now = q.solve(n, m, t);
        if (now > ans) ans = now, anst = mas[i].first;
      }
    }
    cout << ans << ' ' << anst << '\n';
  }
}
