#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXP = 212345;
struct Bit {
  vector<ll> tree;
  Bit() {}
  Bit(int size) : tree(size + 1) {}
  ll getc(int end) {
    ll sum = 0ll;
    for (end++; end > 0; end -= end & -end) sum += tree[end];
    return sum;
  }
  void update(int pos, ll delta) {
    for (pos++; pos < tree.size(); pos += pos & -pos) tree[pos] += delta;
  }
};
Bit cnt(MAXP);
Bit cost(MAXP);
vector<int> p_by_value[MAXP];
int n, m;
ll t;
ll sumFirst(int k) {
  if (k == 0) return 0;
  int lb = 0;
  int ub = MAXP - 1;
  while (lb < ub) {
    int mid = (lb + ub) / 2;
    int q = cnt.getc(mid);
    if (q < k) {
      lb = mid + 1;
    } else if (q > k) {
      ub = mid - 1;
    } else {
      return cost.getc(mid);
    }
  }
  return cost.getc(lb);
}
ll minTime(int k) {
  if (k == 0) return 0;
  int stops = (k + m - 1) / m - 1;
  int rep = stops * m;
  return sumFirst(k) + sumFirst(rep);
}
int fastSimulation() {
  int lb = 0;
  int ub = cnt.getc(MAXP - 1);
  while (lb < ub) {
    int mid = (lb + ub + 1) / 2;
    if (minTime(mid) <= t) {
      lb = mid;
    } else {
      ub = mid - 1;
    }
  }
  return lb;
}
int main() {
  ios::sync_with_stdio(false);
  int ntc;
  cin >> ntc;
  for (int tc = 0; tc < ntc; tc++) {
    cin >> n >> m >> t;
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
      cin >> p[i];
      p_by_value[p[i]].push_back(i);
    }
    sort(p.begin(), p.end());
    p.erase(unique(p.begin(), p.end()), p.end());
    int best_ans = 0;
    int best_d = 1;
    for (int i : p) {
      for (auto& x : p_by_value[i]) {
        cnt.update(x, 1);
        cost.update(x, i);
      }
      int sub_ans = fastSimulation();
      if (sub_ans > best_ans) {
        best_ans = sub_ans;
        best_d = i;
      }
    }
    cout << best_ans << ' ' << best_d << endl;
    for (int i : p) {
      for (auto& x : p_by_value[i]) {
        cnt.update(x, -1);
        cost.update(x, -i);
      }
      p_by_value[i].clear();
    }
  }
}
