#include <bits/stdc++.h>
struct DP {
  int c;
  int s;
  bool operator<(const DP& other) const {
    return (this->c > other.c) || (this->c == other.c && this->s < other.s);
  }
};
int main() {
  int nrTests;
  scanf("%d", &nrTests);
  for (int t = 1; t <= nrTests; t++) {
    int n, p, k;
    scanf("%d%d%d", &n, &p, &k);
    std::vector<int> sorter;
    for (int i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      sorter.push_back(x);
    }
    std::sort(sorter.begin(), sorter.end());
    int count[2 + n], sum[2 + n];
    std::set<DP> mins;
    for (int i = 0; i < k - 1; i++) {
      if (sorter[i] == sorter[0] && i != 0)
        count[i] = (i + 1) * count[0];
      else
        count[i] = (sorter[0] <= p);
      sum[i] = count[i] * sorter[0];
    }
    mins.insert({count[0], sum[0]});
    if (sorter[k - 1] <= p) {
      count[k - 1] = (sorter[k - 1] <= p) * k;
      sum[k - 1] = (sorter[k - 1] <= p) * sorter[k - 1];
      mins.insert({count[k - 1], sum[k - 1]});
    } else {
      count[k - 1] = count[0];
      sum[k - 1] = sum[0];
    }
    for (int i = k; i < n; i++) {
      int val1 = (*(mins.begin())).c;
      int val2 = (sorter[i] <= (p - sum[i - k])) * k + count[i - k];
      if (val1 >= val2) {
        count[i] = val1;
        sum[i] = (*(mins.begin())).s;
      } else {
        count[i] = val2;
        sum[i] = (sorter[i] <= (p - sum[i - k])) * sorter[i] + sum[i - k];
      }
      mins.insert({count[i], sum[i]});
    }
    printf("%d\n", count[n - 1]);
  }
  return 0;
}
