#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int times = 1;
  cin >> times;
  for (int i = 0; i < times; i++) {
    solve();
    cout << '\n';
  }
  return 0;
}
long long a, b, c, d, e, f, g, h;
long long arr[500000 + 50];
void solve() {
  cin >> a >> b >> c;
  for (int i = 1; i <= a; i++) cin >> arr[i];
  sort(arr + 1, arr + a + 1);
  long long dp[a + 50][2];
  for (int i = 1; i <= a; i++) dp[i][0] = dp[i][1] = 21474836477777;
  dp[0][0] = dp[0][1] = 0;
  for (int i = 1; i <= a; i++) {
    if (i > 0) {
      dp[i][0] = min(dp[i][0], dp[i - 1][0] + arr[i]);
      dp[i][0] = min(dp[i][0], dp[i - 1][1] + arr[i]);
    }
    if (i >= c) {
      dp[i][1] = min(dp[i][1], dp[i - c][0] + arr[i]);
      dp[i][1] = min(dp[i][1], dp[i - c][1] + arr[i]);
    }
  }
  int ans = 0;
  for (int i = 1; i <= a; i++) {
    if (dp[i][0] <= b || dp[i][1] <= b) ans = i;
  }
  cout << ans;
}
