#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); }
const int maxn = 1e6 + 7;
const long long inf = 1e15;
const long long md = 1e9 + 7;
long long gcd(long long x, long long y) {
  if (x < y) return gcd(y, x);
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long bit[maxn];
int N;
long long pos[maxn];
long long p[maxn];
long long ST[maxn + 200];
void clr() {
  fill(bit, bit + N + 1, 0);
  fill(pos, pos + N + 1, 0);
  fill(ST, ST + 4 * N + 1, 0);
}
long long qrypos(int x) {
  long long ans = 0;
  while (x > 0) {
    ans += pos[x];
    x -= x & (-x);
  }
  return ans;
}
void updpos(int x, long long v) {
  while (x <= N) {
    pos[x] += v;
    x += x & (-x);
  }
}
long long qry(int x) {
  long long ans = 0;
  while (x > 0) {
    ans += bit[x];
    x -= x & (-x);
  }
  return ans;
}
void upd(int x, long long v) {
  while (x <= N) {
    bit[x] += v;
    x += x & (-x);
  }
}
int n, m;
long long t;
vector<pair<long long, int> > v;
void useg(int x, int l, int r, int p) {
  if (l == r) {
    ST[x]++;
    return;
  }
  int mid = (l + r) / 2;
  if (p <= mid)
    useg(x + x, l, mid, p);
  else
    useg(x + x + 1, mid + 1, r, p);
  ST[x] = ST[x + x] + ST[x + x + 1];
}
int crawl(int x, int l, int r, int k) {
  if (l == r) return l;
  int a = ST[x + x];
  int mid = (l + r) / 2;
  if (k <= a) return crawl(x + x, l, mid, k);
  return crawl(x + x + 1, mid + 1, r, k - a);
}
int findpos(int z) {
  if (z == 0) return 0;
  return crawl(1, 1, n, z);
}
long long most() {
  int tn = qrypos(N);
  if (tn == 0) return 0;
  int l = 0, r = n;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    long long second = qry(mid);
    tn = qrypos(mid);
    int last = tn - tn % m;
    if (last == tn) last = tn - m;
    int fp = findpos(last);
    second = second + qry(fp);
    if (second <= t) {
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  return qrypos(l);
}
void solve() {
  cin >> n >> m;
  cin >> t;
  N = n + 10;
  clr();
  v.clear();
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    v.push_back({p[i], i});
  }
  sort(v.begin(), v.end());
  long long bd = 1, bw = 0;
  for (int i = 0; i < n;) {
    int d = v[i].first;
    int j = i - 1;
    while (j + 1 < n && v[j + 1].first == v[i].first) {
      j++;
      upd(v[j].second, v[j].first);
      updpos(v[j].second, 1);
      useg(1, 1, n, v[j].second);
    }
    int w = most();
    if (w > bw) {
      bd = d;
      bw = w;
    }
    i = j + 1;
  }
  cout << bw << " " << bd << "\n";
}
int main() {
  {
    ios ::sync_with_stdio(false);
    cin.tie(0);
  };
  int T;
  cin >> T;
  while (T--) solve();
}
