#include <bits/stdc++.h>
using namespace std;
long long t, n, m, cap, lis[200500], high, low;
long long f(long long x) {
  long long res = 0, cnt = 0, buf = 0;
  for (int i = (0); i <= ((int)(n)-1); i++)
    if (lis[i] <= x) {
      if (!cnt) {
        res += buf;
        buf = 0;
      }
      cnt++;
      buf += lis[i];
      res += lis[i];
      if (cnt == m) {
        cnt = 0;
      }
    }
  return res;
}
long long g(long long x) {
  long long res = 0, task = 0, cnt = 0, buf = 0;
  for (int i = (0); i <= ((int)(n)-1); i++)
    if (lis[i] <= x) {
      if (!cnt) {
        res += buf;
        buf = 0;
      }
      if (res + lis[i] > cap) break;
      res += lis[i];
      cnt++;
      buf += lis[i];
      task++;
      if (cnt == m) {
        cnt = 0;
      }
    }
  return task;
}
int main() {
  ios::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> n >> m >> cap;
    for (int i = (0); i <= ((int)(n)-1); i++) cin >> lis[i];
    high = cap, low = 1;
    while (high > low) {
      long long chs = (high + low) / 2;
      if (f(chs) > cap)
        high = chs;
      else
        low = chs + 1;
    }
    long long gh = g(high), gh1 = g(high - 1);
    if (gh > gh1 || high == 1)
      cout << gh << ' ' << high << endl;
    else
      cout << gh1 << ' ' << high - 1 << endl;
  }
}
