#include <bits/stdc++.h>
using namespace std;
int64_t m, t;
int64_t max_tasks = 0;
int64_t max_p = 0;
int64_t count_time(vector<int64_t>& p, int64_t d, bool br = false) {
  int64_t t_sum = 0;
  int64_t m_cur = 0;
  int64_t last_sum = 0;
  max_tasks = 0;
  for (size_t i = 0; i < p.size(); ++i) {
    if (p[i] <= d) {
      if (br) {
        if (t_sum + p[i] > t) {
          break;
        }
      }
      t_sum += p[i];
      ++max_tasks;
      last_sum += p[i];
      ++m_cur;
    }
    if (m_cur == m) {
      m_cur = 0;
      if (br) {
        if (t_sum + last_sum > t) {
          break;
        }
      }
      t_sum += last_sum;
      last_sum = 0;
    }
  }
  return t_sum;
}
int64_t bin_search(vector<int64_t>& p) {
  int64_t l = 0, r = max_p + 1;
  while (r - l > 1) {
    int64_t mid = (l + r) / 2;
    int64_t cur_time = count_time(p, mid);
    if (cur_time > t) {
      r = mid;
    } else {
      l = mid;
    }
  }
  return l;
}
int main() {
  int64_t c;
  cin >> c;
  while (c--) {
    int64_t n;
    cin >> n >> m >> t;
    vector<int64_t> p(n);
    max_p = 0;
    for (int64_t i = 0; i < n; ++i) {
      cin >> p[i];
      max_p = std::max(p[i], max_p);
    }
    auto l = bin_search(p);
    auto v1 = count_time(p, l, true);
    int64_t m1 = max_tasks;
    auto v2 = count_time(p, l + 1, true);
    if (max_tasks > m1 && v2 <= t) {
      cout << max_tasks << ' ' << std::min(l + 1, t) << '\n';
    } else {
      cout << m1 << ' ' << std::min(l, t) << '\n';
    }
  }
}
