#include <bits/stdc++.h>
using namespace std;
const long long N = 100001;
void snum(long long &a) { scanf("%lld", &a); }
void snum(long long &a, long long &b) { scanf("%lld %lld", &a, &b); }
void snum(long long &a, long long &b, long long &c) {
  scanf("%lld %lld %lld", &a, &b, &c);
}
void snum(long long &a, long long &b, long long &c, long long &d) {
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
}
vector<long long> pos[N * 2];
vector<long long> tree_cnt;
vector<long long> tree_ac;
set<long long> s;
long long query_cnt(long long pos) {
  long long sum = 0;
  while (pos > 0) {
    sum += tree_cnt[pos];
    pos -= (-pos & pos);
  }
  return sum;
}
void update_cnt(long long pos, long long val, long long n) {
  while (pos < n) {
    tree_cnt[pos] += val;
    pos += (-pos & pos);
  }
  return;
}
long long query_ac(long long pos) {
  long long sum = 0;
  while (pos > 0) {
    sum += tree_ac[pos];
    pos -= (-pos & pos);
  }
  return sum;
}
void update_ac(long long pos, long long val, long long n) {
  while (pos < n) {
    tree_ac[pos] += val;
    pos += (-pos & pos);
  }
  return;
}
long long bbb(long long l, long long r, long long val) {
  while (l != r) {
    long long med = (l + r) / 2;
    if (query_cnt(med) < val) {
      l = med + 1;
    } else {
      r = med;
    }
  }
  return l;
}
long long f(long long x, long long n, long long m) {
  long long prob = query_cnt(x);
  long long lim;
  if (prob % m == 0) {
    lim = prob - m;
  } else {
    lim = prob - prob % m;
  }
  long long exacto = bbb(0, x, lim);
  long long ans = query_ac(x) + query_ac(exacto);
  return ans;
}
long long bb(long long l, long long r, long long t, long long n, long long m) {
  while (l != r) {
    long long med = (l + r) / 2;
    if (f(med, n, m) <= t) {
      l = med + 1;
    } else {
      r = med;
    }
  }
  if (f(l, n, m) > t) {
    l--;
  }
  return l;
}
void solve() {
  tree_cnt.clear();
  tree_ac.clear();
  s.clear();
  long long n, m, t;
  snum(n, m, t);
  tree_cnt.resize(n + 1, 0);
  tree_ac.resize(n + 1, 0);
  long long x;
  for (long long i = 1; i <= n; i++) {
    snum(x);
    s.insert(x);
    pos[x].push_back(i);
  }
  long long ans = 0;
  long long rp = t;
  for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {
    for (long long i = 0; i < pos[*it].size(); i++) {
      update_cnt(pos[*it][i], 1, n + 1);
      update_ac(pos[*it][i], *it, n + 1);
    }
    long long pp = bb(1, n, t, n, m);
    long long aux = query_cnt(pp);
    if (ans < aux) {
      ans = aux;
      rp = *it;
    }
  }
  printf("%lld %lld\n", ans, rp);
  for (set<long long>::iterator it = s.begin(); it != s.end(); it++) {
    pos[*it].clear();
  }
  return;
}
int main() {
  long long t;
  snum(t);
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
