#include <bits/stdc++.h>
using namespace std;
pair<bool, long long> test2(long long t, vector<long long> &arr, long long m,
                            long long d) {
  long long sum = 0;
  long long count = 0;
  long long tSum = 0;
  long long num = 0;
  bool flag = true;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] <= d) {
      if (count == m) {
        sum += tSum;
        tSum = 0;
        count = 0;
      }
      if (sum + arr[i] <= t) {
        sum += arr[i];
        tSum += arr[i];
        count++;
        num++;
      } else {
        flag = false;
        break;
      }
    }
  }
  return {flag, num};
}
bool test(long long t, vector<long long> &arr, long long m, long long d) {
  long long sum = 0;
  long long count = 0;
  long long tSum = 0;
  for (int i = 0; i < arr.size(); i++) {
    if (arr[i] <= d) {
      if (count == m) {
        sum += tSum;
        tSum = 0;
        count = 0;
      }
      sum += arr[i];
      tSum += arr[i];
      count++;
    }
  }
  return sum <= t;
}
long long bp(long long t, vector<long long> &arr, long long m) {
  long long l = 0;
  long long r = 1e17;
  while (l + 1 < r) {
    long long mid = (l + r) / 2;
    if (test(t, arr, m, mid)) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  if (test(t, arr, m, r)) return r;
  return l;
}
void f() {
  long long n, m, t;
  cin >> n >> m >> t;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long d = bp(t, arr, m);
  pair<bool, long long> num = test2(t, arr, m, d);
  pair<bool, long long> num2 = test2(t, arr, m, d + 1);
  while (num.second < num2.second) {
    d++;
    num = num2;
    num2 = test2(t, arr, m, d + 1);
  }
  cout << num.second << " " << min(d, t) << endl;
}
int main() {
  long long c;
  cin >> c;
  for (int q = 0; q < c; q++) {
    f();
  }
  return 0;
}
