#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
int main() {
  int t;
  scanf("%d", &t);
  for (int caso = 1; caso <= t; caso++) {
    int n, p, k = 2;
    scanf("%d%d%d", &n, &p, &k);
    vector<int> v(n);
    for (int i = 0; i < n; i++) scanf("%d", &v[i]);
    sort(begin(v), end(v));
    int ans = 0, taken = 0;
    for (int i = 0; i < k; i++) {
      int sum = taken;
      if (sum > p) break;
      int cnt = i;
      for (int j = i + k - 1; j < n; j += k) {
        if (sum + v[j] <= p) {
          cnt += k;
          sum += v[j];
        } else
          break;
      }
      taken += v[i];
      ans = max(ans, cnt);
    }
    printf("%d\n", ans);
  }
  return 0;
}
