#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int p[maxn];
int main() {
  int T, n, len, c, l, r, m, i, g, gg;
  long long t, x, y, xx;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%lld", &n, &len, &t);
    l = 1e9;
    for (i = 1; i <= n; i++)
      scanf("%d", &p[i]), l = min(l, p[i]), r = max(r, p[i]);
    l++;
    r = min((long long)r, t);
    while (l <= r) {
      m = (l + r) >> 1;
      y = 0;
      x = 0;
      c = 0;
      for (i = 1; i <= n; i++)
        if (p[i] <= m) {
          x += p[i];
          y += p[i];
          c++;
          if (c == len) {
            y += x;
            xx = x;
            x = 0;
            c = 0;
          }
        }
      if (c == 0) y -= xx;
      if (y > t)
        r = m - 1;
      else
        l = m + 1;
    }
    if (r == 0) r++;
    c = 0;
    y = 0;
    x = 0;
    g = 0;
    for (i = 1; i <= n; i++)
      if (p[i] <= r) {
        x += p[i];
        y += p[i];
        if (y > t) break;
        g++;
        c++;
        if (c == len) {
          y += x;
          if (y > t) break;
          xx = x;
          x = 0;
          c = 0;
        }
      }
    gg = g;
    c = 0;
    y = 0;
    x = 0;
    g = 0;
    for (i = 1; i <= n; i++)
      if (p[i] <= r + 1) {
        x += p[i];
        y += p[i];
        if (y > t) break;
        g++;
        c++;
        if (c == len) {
          y += x;
          if (y > t) break;
          xx = x;
          x = 0;
          c = 0;
        }
      }
    if (gg >= g)
      printf("%d %d\n", gg, r);
    else
      printf("%d %d\n", g, r + 1);
  }
  return 0;
}
