#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using pll = pair<ll, ll>;
using vb = vector<bool>;
int main() {
  ios::sync_with_stdio(false);
  ll t;
  cin >> t;
  for (ll tests = (0); tests < (t); tests++) {
    ll n, p, k;
    cin >> n >> p >> k;
    vl a(n + 1);
    for (ll i = (1); i < (n + 1); i++) cin >> a[i];
    sort(begin(a), end(a));
    vl erg(n + 1, -1);
    erg[0] = p;
    ll biggest = 0;
    for (ll i = (0); i < (n); i++) {
      if (erg[i] != -1) {
        biggest = i;
        if (erg[i] - a[i + 1] >= 0) {
          erg[i + 1] = max(erg[i + 1], erg[i] - a[i + 1]);
        }
        if (i + k < n + 1) {
          if (erg[i] - a[i + k] >= 0) {
            erg[i + k] = max(erg[i + k], erg[i] - a[i + k]);
          }
        }
      }
    }
    if (erg[n] != -1) {
      biggest = n;
    }
    cout << biggest << endl;
  }
  return 0;
}
