#include <bits/stdc++.h>
using namespace std;
struct P {
  int x, y;
  bool operator<(const P &a) const {
    if (x != a.x) return x < a.x;
    return y < a.y;
  }
};
long long x, y, z, mod = 998244353;
vector<int> v, v1;
int i, n, m, k, a, d, b, c;
int e[211111];
int o[212222];
long long l[22221];
int j[5556];
stack<P> s;
queue<int> q;
queue<int> q1;
P u[1];
char r[1], r1[3];
bool as(P a, P b) { return a.y < b.y; }
int main() {
  int kk;
  scanf("%d", &kk);
  for (int ttt = 1; ttt <= kk; ttt++) {
    scanf("%d %d %lld", &a, &b, &x);
    for (int t = 1; t <= a; e[t] = o[t], t++) scanf("%d", &o[t]);
    sort(e + 1, e + a + 1);
    int n = 0, m = a;
    for (; n < m;) {
      int h = (n + m) / 2 + 1, k = 0, i = 0;
      long long y = 0, z = 0;
      for (int t = 1; k < h && t <= a; t++)
        if (o[t] <= e[h]) {
          i++;
          y += o[t], z += o[t];
          k++;
          if (k >= h) break;
          if (i == b) i = 0, y += z, z = 0;
        }
      if (y <= x)
        n = h;
      else
        m = h - 1;
    }
    printf("%d %d\n", n, max(e[n], 1));
  }
}
