#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433832795l;
template <typename T>
inline auto sqr(T x) -> decltype(x * x) {
  return x * x;
}
template <typename T>
inline T abs(T x) {
  return x > T() ? x : -x;
}
template <typename T1, typename T2>
inline bool umx(T1& a, T2 b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T1, typename T2>
inline bool umn(T1& a, T2 b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
struct Input {
  int n, m;
  long long t;
  vector<int> a;
  bool read() {
    if (!(cin >> n >> m >> t)) {
      return false;
    }
    a.resize(n);
    for (int& x : a) {
      cin >> x;
    }
    return true;
  }
  void init(const Input& input) { *this = input; }
};
struct Data : Input {
  pair<int, int> res;
  void write() { cout << res.first << " " << res.second << "\n"; }
  virtual void solve() {}
  virtual void clear() { *this = Data(); }
};
struct Solution : Data {
  long long check(int d) {
    vector<int> b;
    for (int x : a) {
      if (x > d) {
        continue;
      }
      b.push_back(x);
    }
    long long t = 0;
    for (int i = 0; i < ((int)(b).size());) {
      long long bt = 0;
      for (int j = 0; i < ((int)(b).size()) && j < m; ++i, ++j) {
        bt += b[i];
      }
      t += bt;
      if (i != ((int)(b).size())) {
        t += bt;
      }
    }
    return t;
  }
  int get(int d) {
    long long bt = 0, ct = 0;
    int k = 0;
    for (int x : a) {
      if (x > d) {
        continue;
      }
      ct += x;
      bt += x;
      if (ct > t) {
        return k;
      }
      ++k;
      if (k % m == 0) {
        ct += bt;
        bt = 0;
      }
    }
    return k;
  }
  void solve() {
    vector<int> b = a;
    sort((b).begin(), (b).end());
    int left = -1, right = min<long long>(t, b.back());
    while (left + 1 < right) {
      int middle = (left + right) / 2;
      if (check(middle) >= t) {
        right = middle;
      } else {
        left = middle;
      }
    }
    res = {get(left), left};
    res = max(res, make_pair(get(right), right));
  }
  void clear() { *this = Solution(); }
};
Solution sol;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout.setf(ios::showpoint | ios::fixed);
  cout.precision(20);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    sol.read();
    sol.solve();
    sol.write();
    sol.clear();
  }
  return 0;
}
