#include <bits/stdc++.h>
const int N = 2e5 + 5;
using namespace std;
int n, m, Test;
int b[N];
pair<int, int> a[N];
long long t;
int check(int k) {
  int mi = a[k].first, dem = 0, cnt = 0;
  long long s = 0, Time = 0;
  for (int i = 1; i <= n; i++)
    if (b[i] <= mi) {
      if (Time + b[i] > t) break;
      Time += b[i];
      s += b[i];
      dem++;
      cnt++;
      if (cnt == m) {
        if (Time + s <= t)
          Time += s;
        else
          break;
        cnt = 0;
        s = 0;
      }
    }
  if (dem >= k) return 1;
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> Test;
  a[0].first = 1;
  while (Test--) {
    cin >> n >> m >> t;
    for (int i = 1; i <= n; i++) {
      cin >> a[i].first;
      b[i] = a[i].first;
      a[i].second = i;
    }
    sort(a + 1, a + n + 1);
    int i = 1, j = n, res = 0;
    while (i <= j) {
      int mid = (i + j) / 2;
      if (check(mid)) {
        res = mid;
        i = mid + 1;
      } else
        j = mid - 1;
    }
    cout << res << ' ' << a[res].first << endl;
  }
}
