#include <bits/stdc++.h>
const double EPS = 0.0000000001;
const long long mod1 = 998244353;
const long long mod2 = 1000000007;
const long long mod3 = 1000000009;
const long long mod4 = 228228227;
const long long inf = 100000000000000;
using namespace std;
signed main() {
  long long t;
  cin >> t;
  for (long long q = 0; q < t; q++) {
    long long n, a, b;
    cin >> n >> a >> b;
    vector<long long> v(n);
    for (long long i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    long long dp[n];
    dp[0] = v[0];
    for (long long i = 1; i < n; i++) {
      dp[i] = inf;
      if ((i - b) == -1) {
        dp[i] = v[i];
      }
      if ((i - b) >= 0) dp[i] = dp[i - b] + v[i];
      dp[i] = min(dp[i], dp[i - 1] + v[i]);
    }
    for (long long i = n - 1; i >= 0; i--) {
      if (dp[i] <= a) {
        cout << i + 1 << endl;
        break;
      }
    }
    if (dp[0] > a) cout << 0 << endl;
  }
}
