#include <bits/stdc++.h>
using namespace std;
int n, m;
long long t;
int values[200013];
pair<int, int> ordered[200013];
pair<int, int> check(int d) {
  int solved = 0;
  long long time = 0;
  long long lastTime = 0;
  for (int i = 0; i < n; i++) {
    if (values[i] <= d) {
      if (time + values[i] > t) return make_pair(1, solved);
      time += values[i];
      solved++;
      lastTime += values[i];
      if (solved % m == 0) {
        time += lastTime;
        lastTime = 0;
      }
    }
  }
  return make_pair(0, solved);
}
int main() {
  if (fopen("FILENAME.in", "r")) {
    freopen("FILENAME.in", "r", stdin);
    freopen("FILENAME.out", "w", stdout);
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int c;
  cin >> c;
  while (c--) {
    cin >> n >> m >> t;
    for (int i = 0; i < n; i++) {
      cin >> values[i];
    }
    int start = 0;
    int end = 200013;
    int answer = 0;
    int position = 0;
    while (start <= end) {
      int mid = (start + end) / 2;
      pair<int, int> result = check(mid);
      if (answer < result.second) {
        answer = result.second;
        position = mid;
      }
      if (result.first == 0) {
        start = mid + 1;
      } else {
        end = mid - 1;
      }
    }
    pair<int, int> result = check(start);
    if (answer < result.second) {
      answer = result.second;
      position = start;
    }
    result = check(end);
    if (answer < result.second) {
      answer = result.second;
      position = end;
    }
    cout << answer << ' ' << max(1LL, min(t, 1LL * position)) << '\n';
  }
}
