#include <bits/stdc++.h>
using namespace std;
vector<int> v, w;
int m;
long long int f(int d, int target) {
  long long int timeSpent = 0;
  long long int totDone = 0;
  long long int koytaDone = 0;
  long long int lastSpent = 0;
  for (int i = 0; i < v.size(); i++) {
    if (v[i] <= d) {
      timeSpent += v[i];
      lastSpent += v[i];
      koytaDone++;
      totDone++;
      if (totDone == target) return timeSpent;
    }
    if (koytaDone == m) {
      koytaDone = 0;
      timeSpent += lastSpent;
      lastSpent = 0;
    }
  }
  return LLONG_MAX / 3;
}
int main() {
  int t, n, inp;
  long long int tot;
  scanf("%d", &t);
  while (t--) {
    v.clear();
    w.clear();
    scanf("%d %d", &n, &m);
    cin >> tot;
    while (n--) {
      scanf("%d", &inp);
      v.push_back(inp);
      w.push_back(inp);
    }
    sort(w.begin(), w.end());
    int lo = 1, hi = w.size(), ans = 0, ans_d = 1;
    while (lo <= hi) {
      int mid = (lo + hi) / 2;
      int tem_d = w[mid - 1];
      if (f(tem_d, mid) <= tot) {
        ans = mid;
        ans_d = tem_d;
        lo = mid + 1;
      } else
        hi = mid - 1;
    }
    cout << ans << " " << ans_d << '\n';
  }
  return 0;
}
