#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n, p, k, p1;
    cin >> n >> p >> k;
    p1 = p;
    vector<long long> v(n);
    for (long long i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());
    long long count = 0;
    for (long long i = 1; i < n; i += 2) {
      if (v[i] <= p) {
        count += 2;
        p -= v[i];
      }
    }
    if (n % k != 0 && v[n - 1] <= p) count++;
    long long count1 = 0;
    p = p1;
    if (v[0] <= p) {
      count1 = 1;
      p -= v[0];
    }
    for (long long i = 2; i < n; i += 2) {
      if (v[i] <= p) {
        count1 += 2;
        p -= v[i];
      }
    }
    if (n % k == 0 && v[n - 1] <= p) count1++;
    cout << max(count, count1) << endl;
  }
}
