#include <bits/stdc++.h>
using namespace std;
const long long inf = (long long)1e15;
const long long mod = (long long)1e9 + 7;
const double eps = (double)1e-9;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 200500;
long long lim;
int T, n, m, a[N], p[N];
inline bool cmp(int i, int j) {
  if (a[i] == a[j]) return i < j;
  return a[i] < a[j];
}
inline bool check(int x) {
  long long sum = 0;
  int cur = 0;
  int limit = (x - 1) / m * m;
  for (int i = 1; i <= n; i++) {
    if (a[i] <= a[p[x]] && cur < x) {
      sum += a[i];
      cur++;
      if (cur <= limit) sum += a[i];
    }
  }
  return sum <= lim;
}
int main() {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> T;
  while (T--) {
    cin >> n >> m >> lim;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      p[i] = i;
    }
    sort(p + 1, p + 1 + n, &cmp);
    int l = 1, r = n, ans = 0;
    while (l <= r) {
      int mid = (l + r) >> 1;
      if (check(mid)) {
        ans = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    cout << ans << " " << max(a[p[ans]], 1) << endl;
  }
  return 0;
}
