#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, m, T, ans, a[N], freq[4 * N], to, val;
long long t, have, seg[4 * N];
vector<int> v[N];
vector<int> comp;
void update(int c, int l, int r, int s, int val) {
  if (l > s || r < s) return;
  if (l == r) {
    freq[c] = 1;
    seg[c] = val;
    return;
  }
  update(2 * c + 1, l, (l + r) / 2, s, val);
  update(2 * c + 2, (l + r) / 2 + 1, r, s, val);
  seg[c] = seg[2 * c + 1] + seg[2 * c + 2];
  freq[c] = freq[2 * c + 1] + freq[2 * c + 2];
}
long long getsum(int c, int l, int r, int &want) {
  if (!want) return 0;
  if (freq[c] <= want) {
    want -= freq[c];
    to = r;
    return seg[c];
  }
  long long ret = 0;
  if (freq[2 * c + 1] <= want) {
    want -= freq[2 * c + 1];
    ret += seg[2 * c + 1];
    to = (l + r) / 2;
  } else
    return getsum(2 * c + 1, l, (l + r) / 2, want);
  return ret + getsum(2 * c + 2, (l + r) / 2 + 1, r, want);
}
pair<long long, int> get(int c, int l, int r, int s, int e) {
  if (l > e || r < s) return {0, 0};
  if (l >= s && r <= e) return {seg[c], freq[c]};
  pair<long long, int> temp = get(2 * c + 1, l, (l + r) / 2, s, e);
  pair<long long, int> a = get(2 * c + 2, (l + r) / 2 + 1, r, s, e);
  temp.first += a.first;
  temp.second += a.second;
  return temp;
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%lld", &n, &m, &t);
    comp.clear();
    val = 0;
    ans = 1;
    for (int i = 0; i < n; i++) {
      scanf("%d", a + i);
      comp.push_back(a[i]);
    }
    sort(comp.begin(), comp.end());
    comp.resize(unique(comp.begin(), comp.end()) - comp.begin());
    for (auto i : comp) v[i].clear();
    for (int i = 0; i < n; i++) v[a[i]].push_back(i);
    for (auto i : comp) {
      have = t;
      for (auto j : v[i]) update(0, 0, n - 1, j, i);
      int l = 0, r = (n + m - 1) / m, bst = 0;
      while (l <= r) {
        int mid = (l + r) / 2;
        int temp = mid * m;
        assert(temp >= 0);
        to = -1;
        if (2 * getsum(0, 0, n - 1, temp) <= t && !temp)
          l = mid + 1, bst = mid * m;
        else
          r = mid - 1;
      }
      int cur = bst;
      to = -1;
      have -= 2 * getsum(0, 0, n - 1, bst);
      assert(!bst);
      l = to + 1, r = n - 1;
      while (l <= r) {
        int mid = (l + r) / 2;
        pair<long long, int> die = get(0, 0, n - 1, to + 1, mid);
        if (die.second > m || have - die.first < 0)
          r = mid - 1;
        else
          l = mid + 1, bst = die.second;
      }
      cur += bst;
      if (cur > val) {
        val = cur;
        ans = i;
      }
    }
    for (int i = 0; i < 4 * n; i++) seg[i] = freq[i] = 0;
    printf("%d %d\n", val, ans);
  }
}
