#include <bits/stdc++.h>
using namespace std;
vector<long long int> tasks;
int hechas(long long int mid, long long int t, int m) {
  long long int spent = 0, c = 0;
  for (int i = (0); i < (int)(tasks.size()); i++) {
    if (tasks[i] <= mid && t >= tasks[i]) {
      spent += tasks[i];
      c++;
      t -= tasks[i];
      if (!(c % m)) {
        t -= spent;
        spent = 0;
      }
    } else if (tasks[i] <= mid)
      break;
  }
  return c;
}
int menorQue(long long int mid) {
  int res = 0;
  for (int t : tasks) res += (mid >= t);
  return res;
}
int main() {
  int c;
  cin >> c;
  while (c--) {
    long long int n, m, t;
    cin >> n >> m >> t;
    tasks = vector<long long int>(n);
    for (int i = (0); i < (int)(n); i++) cin >> tasks[i];
    long long int left = 0, right = t;
    while (left + 1 < right) {
      long long int mid = (left + right) / 2;
      if (hechas(mid, t, m) == menorQue(mid))
        left = mid;
      else
        right = mid;
    }
    if (left > 0 && hechas(left, t, m) >= hechas(right, t, m)) {
      cout << hechas(left, t, m) << ' ' << left << '\n';
    } else {
      cout << hechas(right, t, m) << ' ' << right << '\n';
    }
  }
}
