#include <bits/stdc++.h>
using namespace std;
long long n, m, t;
int arr[200005];
int arr2[200005];
bool bisa(int mid) {
  long long solved = 0;
  long long sum = 0;
  long long cur = 0;
  long long cnt = 0;
  for (int i = 0; i < n; i++) {
    if (arr[i] > arr2[mid]) continue;
    if (arr[i] + sum <= t) {
      solved++;
      cnt++;
      sum += arr[i];
      cur += arr[i];
      if (cnt >= m) {
        sum += cur;
        cnt = 0;
        cur = 0;
      }
    } else {
      break;
    }
  }
  return (mid + 1) <= solved;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> m >> t;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      arr2[i] = arr[i];
    }
    sort(arr2, arr2 + n);
    int l = 0;
    int r = n - 1;
    int ans = 0;
    int ans_d = 1;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (bisa(mid)) {
        l = mid + 1;
        ans = mid + 1;
        ans_d = arr2[mid];
      } else {
        r = mid - 1;
      }
    }
    cout << ans << " " << ans_d << endl;
  }
  return 0;
}
