#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 2e5 + 10;
namespace seg {
int qt[4 * MAX];
long long sum[4 * MAX];
int n;
void build(int n2) {
  n = n2;
  for (int i = 0; i < 4 * n; i++) qt[i] = sum[i] = 0;
}
void update(int a, int x, int p = 1, int l = 0, int r = n - 1) {
  if (a == l and r == a) {
    qt[p] = 1;
    sum[p] = x;
    return;
  }
  if (a < l or r < a) return;
  int m = (l + r) / 2;
  update(a, x, 2 * p, l, m);
  update(a, x, 2 * p + 1, m + 1, r);
  qt[p] = qt[2 * p] + qt[2 * p + 1];
  sum[p] = sum[2 * p] + sum[2 * p + 1];
}
int query(long long t, int p = 1, int l = 0, int r = n - 1) {
  if (l == r) {
    return qt[p] ? (2 * sum[p] <= t) : 0;
  }
  int m = (l + r) / 2;
  if (2 * sum[2 * p] <= t)
    return qt[2 * p] + query(t - 2 * sum[2 * p], 2 * p + 1, m + 1, r);
  return query(t, 2 * p, l, m);
}
long long get_first(int qtt, int p = 1, int l = 0, int r = n - 1) {
  if (qtt == 0) return 0;
  if (l == r) {
    return sum[p];
  }
  int m = (l + r) / 2;
  if (qt[2 * p] > qtt) return get_first(qtt, 2 * p, l, m);
  return sum[2 * p] + get_first(qtt - qt[2 * p], 2 * p + 1, m + 1, r);
}
int query2(int ignore, long long& t, int p = 1, int l = 0, int r = n - 1) {
  if (t <= 0) return 0;
  if (l == r) {
    if (ignore or !qt[p]) return 0;
    t -= sum[p];
    return t >= 0;
  }
  if (!ignore and sum[p] <= t) {
    t -= sum[p];
    return qt[p];
  }
  int m = (l + r) / 2;
  if (ignore >= qt[2 * p])
    return query2(ignore - qt[2 * p], t, 2 * p + 1, m + 1, r);
  return query2(ignore, t, 2 * p, l, m) + query2(0, t, 2 * p + 1, m + 1, r);
}
}  // namespace seg
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    long long t;
    cin >> n >> m >> t;
    vector<pair<int, int>> v(n);
    for (int i = 0; i < n; i++) {
      cin >> v[i].first;
      v[i].second = i;
    }
    int ans = 0;
    long long opt = t;
    sort(v.begin(), v.end());
    seg::build(n);
    for (int i = 0; i < n; i++) {
      int j = i - 1;
      while (j + 1 < n and v[j + 1].first == v[i].first) {
        j++;
        seg::update(v[j].second, v[j].first);
      }
      int at = seg::query(t) / m * m;
      long long usei = 2 * seg::get_first(at);
      long long tt = t - usei;
      int inc = min(m, seg::query2(at, tt));
      at += inc;
      if (at > ans) {
        ans = at;
        opt = v[i].first;
      }
      i = j;
    }
    cout << ans << " " << opt << '\n';
  }
  exit(0);
}
