#include <bits/stdc++.h>
using namespace std;
void test_case() {
  long long n, p, k;
  cin >> n >> p >> k;
  vector<long long> a(n);
  for (auto &i : a) {
    cin >> i;
  }
  sort(a.begin(), a.end());
  long long dp[n][2];
  memset(dp, 0, sizeof(dp));
  if (p >= a[0]) {
    dp[0][0] = 1;
    dp[0][1] = p - a[0];
  }
  for (long long i = 1; i < n; ++i) {
    dp[i][0] = dp[i - 1][0];
    dp[i][1] = dp[i - 1][1];
    if ((i + 1) < k) {
      if (a[i] <= dp[i - 1][1]) {
        dp[i][0] += 1;
        dp[i][1] = dp[i - 1][1] - a[i];
      }
    } else {
      if (i + 1 == k) {
        if (a[i] <= p) {
          dp[i][0] = k;
          dp[i][1] = p - a[i];
        }
      } else {
        if (a[i] <= dp[i - k][1]) {
          dp[i][0] = dp[i - k][0] + k;
          dp[i][1] = dp[i - k][1] - a[i];
        }
      }
    }
  }
  cout << dp[n - 1][0] << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    test_case();
  }
  return 0;
}
