#include <bits/stdc++.h>
using namespace std;
int a[200005], n, p, k;
bool check(int mid) {
  int cur = 0;
  int last_p = 0;
  int total = 0;
  for (int i = mid; i >= 1; i--) {
    cur++;
    if (!last_p) last_p = a[i];
    if (cur == k) {
      total += last_p;
      last_p = 0;
      cur = 0;
    }
  }
  total += last_p;
  if (total > p)
    return false;
  else
    return true;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> p >> k;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    if (p < a[1]) {
      cout << 0 << endl;
      continue;
    }
    int l = 1;
    int r = n;
    while (l < r) {
      int mid = (l + r + 1) / 2;
      bool flag = check(mid);
      if (flag) {
        l = mid;
      } else
        r = mid - 1;
    }
    cout << l << endl;
  }
}
