#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 1;
int n, p, k, a[N];
bool check(int x) {
  int cost = 0;
  while (x > 0) {
    cost += a[x];
    if (cost > p) return false;
    x -= k;
  }
  return true;
}
int main() {
  int test;
  cin >> test;
  while (test--) {
    cin >> n >> p >> k;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    sort(a + 1, a + n + 1);
    int l = 1, r = n, res = 0;
    while (l <= r) {
      int mid = (l + r) / 2;
      if (check(mid)) {
        res = mid;
        l = mid + 1;
      } else
        r = mid - 1;
    }
    cout << res << '\n';
  }
}
