#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e5 + 5;
int arr[N], n;
long long p, k;
bool check(int mid) {
  int idx = mid - 1;
  long long curr = 0;
  int take = 0;
  while (idx - k + 1 >= 0) {
    take += k;
    curr += arr[idx];
    idx -= k;
  }
  int temp = idx, i = 0;
  while (i <= temp) {
    if (curr + arr[i] <= p)
      curr += arr[i], take++;
    else
      break;
    i++;
  }
  return curr <= p && take == mid;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> p >> k;
    for (auto i = 0; i < (long long)(n); i++) cin >> arr[i];
    sort(arr, arr + n);
    int st = 0, en = n, mid, ret = 0;
    while (st <= en) {
      mid = (st + en) / 2;
      if (check(mid))
        st = mid + 1, ret = mid;
      else
        en = mid - 1;
    }
    cout << ret << '\n';
  }
  return 0;
}
