#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}
	}
	return true;
}

int main()
{
   ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
ll k=1;
ll x=2;
ll next=2;
ll cnt=1;
    while(k!=n+1)
    {
		if((next*next-x)%k==0&&(next)%(k+1)==0)
		{
			cout<<(next*next-x)/(k)<<endl;
			k++;
			x=next;
			next=k+1;
			cnt=2;
		}
		else
		{
			next=next/cnt;
			cnt++;
			next=next*cnt;
		}

	}
}


#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define lli long long int
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}
	}
	return true;
}

int main()
{
   ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll x=2;

for(ll k=1;k<=n;k++)
{
ll ans=(k*(k+1)*(k+1))-(x/k);
x=k*(k+1);
cout<<ans<<endl;
}
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

map<ll, ll> prime_factor(ll a) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= a; i++) {
		while (a % i == 0 && a != 0) {
			ret[i]++;
			a /= i;
		}
	}
	if (a != 1) {
		ret[a]++;
	}
	return ret;
}

ll sq(ll x) {
	ll t = sqrt(x);
	for (ll i = max(0LL, t - 2); i <= t + 2; i++) {
		if (i * i == x) return i;
	}
}

ll power(ll x, ll n) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return power(x * x, n / 2);
	}
	else {
		return x * power(x, n - 1);
	}
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    ll n; scanf("%lld", &n);
    vector<ll> res(n);
    ll cur = 2;
    for (ll i = 1; i <= n; i++) {
		auto mp = prime_factor(cur);
		ll nxt = cur;
		for (auto &p : mp) {
			if (p.second & 1) nxt *= p.first, p.second += 1;
		}
		auto t = prime_factor(i + 1);
		for (auto e : t) {
			if (i != n) {
				if (mp[e.first] < e.second * 2) {
					///cout << mp[e.first]<<" "<<e.first << " " << e.second << endl;
					nxt *= power(e.first, e.second * 2 - mp[e.first]);
					mp[e.first] = e.second * 2;
				}
			}
		}
		//cout << ":"<<nxt << endl;
		printf("%lld\n", (nxt - cur) / (i));
		cur = sq(nxt);
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

map<ll, ll> prime_factor(ll a) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= a; i++) {
		while (a % i == 0 && a != 0) {
			ret[i]++;
			a /= i;
		}
	}
	if (a != 1) {
		ret[a]++;
	}
	return ret;
}

ll sq(ll x) {
	ll t = sqrt(x);
	for (ll i = max(0LL, t - 2); i <= t + 2; i++) {
		if (i * i == x) return i;
	}
}

ll power(ll x, ll n) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return power(x * x, n / 2);
	}
	else {
		return x * power(x, n - 1);
	}
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    ll n; scanf("%lld", &n);
    vector<ll> res(n);
    ll cur = 2;
    for (ll i = 1; i <= n; i++) {
		auto mp = prime_factor(cur);
		ll nxt = cur;
		for (auto &p : mp) {
			if (p.second & 1) nxt *= p.first, p.second += 1;
		}
		auto t = prime_factor(i + 1);
		for (auto e : t) {

			if (mp[e.first] < e.second * 2) {
				///cout << mp[e.first]<<" "<<e.first << " " << e.second << endl;
				nxt *= power(e.first, e.second * 2 - mp[e.first]);
				mp[e.first] = e.second * 2;
			}

		}
		//cout << ":"<<nxt << endl;
		printf("%lld\n", (nxt - cur) / (i));
		cur = sq(nxt);
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    ll n; scanf("%lld", &n);
    ll cur = 2;
    for (ll i = 1; i <= n; i++) {
        ll res = i * (i + 1) * (i + 1) - cur / i;
        printf("%lld\n", res);
        cur = i * (i + 1);
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

constexpr long long MAX = 510000;
map<ll, ll> prime_factor(ll a) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= a; i++) {
		while (a % i == 0 && a != 0) {
			ret[i]++;
			a /= i;
		}
	}
	if (a != 1) {
		ret[a]++;
	}
	return ret;
}

ll sq(ll x) {
	ll t = sqrt(x);
	for (ll i = max(0LL, t - 2); i <= t + 2; i++) {
		if (i * i == x) return i;
	}
}

ll power(ll x, ll n) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return power(x * x, n / 2);
	}
	else {
		return x * power(x, n - 1);
	}
}

bool IsPrime[MAX];
ll MinFactor[MAX]; vector<ll> preprocess(ll n = MAX) {
	vector<ll> res;
	for (ll i = 0; i < n; ++i) IsPrime[i] = true, MinFactor[i] = -1;
	IsPrime[0] = false; IsPrime[1] = false;
	MinFactor[0] = 0; MinFactor[1] = 1;
	for (ll i = 2; i < n; ++i) {
		if (IsPrime[i]) {
			MinFactor[i] = i;
			res.push_back(i);
			for (ll j = i * 2; j < n; j += i) {
				IsPrime[j] = false;
				if (MinFactor[j] == -1) MinFactor[j] = i;
			}
		}
	}
	return res;
}

vector<pair<ll, ll> > fast_prime_factor(ll n) {
	vector<pair<ll, ll> > res;
	while (n != 1) {
		ll prime = MinFactor[n];
		ll exp = 0;
		while (MinFactor[n] == prime) {
			++exp;
			n /= prime;
		}
		res.push_back(make_pair(prime, exp));
	}
	return res;
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
	preprocess();
    ll n; scanf("%lld", &n);
    vector<ll> res(n);
    ll cur = 2;
	auto mp = prime_factor(2);
    for (ll i = 1; i <= n; i++) {
		ll nxt = cur;
		for (auto &p : mp) {
			if (p.second & 1) nxt *= p.first, p.second += 1;
		}
		auto t = fast_prime_factor(i + 1);
		for (auto e : t) {

			if (mp[e.first] < e.second * 2) {
				///cout << mp[e.first]<<" "<<e.first << " " << e.second << endl;
				nxt *= power(e.first, e.second * 2 - mp[e.first]);
				mp[e.first] = e.second * 2;
			}

		}
		//cout << ":"<<nxt << endl;
		printf("%lld\n", (nxt - cur) / (i));
		cur = sq(nxt);
		for (auto& p : mp) {
			p.second /= 2;
		}
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
//constexpr long long mod = 1000000007LL;
constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

map<ll, ll> prime_factor(ll a) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= a; i++) {
		while (a % i == 0 && a != 0) {
			ret[i]++;
			a /= i;
		}
	}
	if (a != 1) {
		ret[a]++;
	}
	return ret;
}

ll sq(ll x) {
	ll t = sqrt(x);
	for (ll i = max(0LL, t - 2); i <= t + 2; i++) {
		if (i * i == x) return i;
	}
}

ll power(ll x, ll n) {
	if (n == 0) {
		return 1;
	}
	if (n % 2 == 0) {
		return power(x * x, n / 2);
	}
	else {
		return x * power(x, n - 1);
	}
}
int main()
{
    /*
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    */
    ll n; scanf("%lld", &n);
    vector<ll> res(n);
    ll cur = 2;
	auto mp = prime_factor(2);
    for (ll i = 1; i <= n; i++) {
		ll nxt = cur;
		for (auto &p : mp) {
			if (p.second & 1) nxt *= p.first, p.second += 1;
		}
		auto t = prime_factor(i + 1);
		for (auto e : t) {

			if (mp[e.first] < e.second * 2) {
				///cout << mp[e.first]<<" "<<e.first << " " << e.second << endl;
				nxt *= power(e.first, e.second * 2 - mp[e.first]);
				mp[e.first] = e.second * 2;
			}

		}
		//cout << ":"<<nxt << endl;
		printf("%lld\n", (nxt - cur) / (i));
		cur = sq(nxt);
		for (auto& p : mp) {
			p.second /= 2;
		}
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long n,k;
void dfs(int u,int x,int ans){
	if(u>n)return;
	for(int i=1;i;i++){
		k = (u+1)*i;
		ans = (k*k-x)/u;
		if(k * k >= x && ans*u==(k*k-x))break;
	}
	cout<<ans<<endl;
	dfs(u+1,k,0);
}
int main(){
	scanf("%lld",&n);
	dfs(1,2,0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long ans,n;
int main(){
    scanf("%lld",&n);
    printf("2\n");
    for(long long i=2;i<=n;++i){
        ans=(i+2)*i*i+1;
        printf("%lld\n",ans);
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;
#define N (1000005)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(v) ((int)(v).size())
#define ed(v) v.end()
#define contains(v,i) (v.find(i)!=v.end())
#define forn(i,a,b) for(ll i = a; i < b; i++)
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define sq(v) ((a)*(a))
#define cb(v) ((a)*(a)*(a))

typedef long long int ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef vector<ll> vi;
typedef map<ll,ll> mll;

int main(){

    fast

    ll n;
    cin >> n;

    ll prev = 1;

    forn(i, 1, n+1){
      ll next = i * (i + 1);
      ll target = next * next;
      // cout << "Next " << next << " Prev " << prev << " Target " << target << endl;
      cout << (target - prev) / i << endl;
      prev = next;
    }

    return 0;
}


            #include<bits/stdc++.h>
            #define ll            long long
            #define pb            push_back
            #define ppb           pop_back
            #define si            set <ll>
            #define endl          '\n'
            #define fr            first
            #define sc            second
            #define mii           map<ll ,ll >
            #define msi           map<string,ll >
            #define mis           map<ll , string>
            #define rep(i,a,b)    for(ll  i=a;i<b;i++)
            #define all(v)        v.begin(),v.end()
            #define sort(v)       sort(all(v))
            #define pii           pair<ll ,ll >
            #define vi            vector<ll >
            #define vii           vector<pair<ll , ll >>
            #define vs            vector<string>
            #define sz(x)         (ll )x.size()
            #define M             1000000007
            #define bs            binary_search
            //#define mp            make_pair
            #define sp(n)         setprecision(n)
            #define spl           " "
            #define arr(a,n)      rep(i,0,n) cin>>a[i]
            #define mod           998244353
            #define show(x,a)     for(auto x:a) cout<<x<<" "; cout<<endl;
            #define N             1000000000
            #define what_is(x)    cout << #x << " is " << x << endl;
            #define time          cout << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
            #define INF           1ll<<32
            using namespace std;
            /*
            ll modularExponentiation(ll x,ll n,ll mm)
            {
                ll result=1;
                while(n>0)
                {
                    if(n % 2 ==1)
                        result=(result * x)%mm;
                    x=(x*x)%mm;
                    n=n/2;
                }
                return result;
            }
            ll modInverse(ll A,ll mm)
            {
                return modularExponentiation(A,mm-2,mm);
            }
                // Disjoll Set DataStructure
                map< ll,ll > parent;         // reserve space for map if n > 10000
                map< ll,ll > urank;

                void create(ll x)
                {
                    parent[x] = x ;
                    urank[x] = 0 ;         // rank = no. of nodes in its subtree
                }

                ll find(ll x)
                {
                    if( parent[x] != x )    //path compression
                    {
                        parent[x] = find(parent[x]) ;
                    }
                    return parent[x];
                }

                void merge(ll x, ll y)
                {
                    ll xroot = find(x);
                    ll yroot = find(y);

                    if( urank[xroot] <= urank[yroot] )    // Union by rank
                    {
                        parent[xroot] = yroot ;
                        urank[yroot] = urank[yroot] + urank[xroot] ;
                    }
                    else
                    {
                        parent[yroot] = xroot;
                        urank[xroot] = urank[xroot] + urank[yroot] ;
                    }
                }
                ll gcd(ll a, ll b)
                {
                    if (a == 0)
                        return b;
                    return gcd(b % a, a);
                }

                ll spf[MAXN];
                void sieve()
                {
                    spf[1] = 1;
                    for (ll i=2; i<MAXN; i++)
                        spf[i] = i;
                    for (ll i=4; i<MAXN; i+=2)
                        spf[i] = 2;

                    for (ll i=3; i*i<MAXN; i++)
                    {
                        if (spf[i] == i)
                        {
                            for (ll j=i*i; j<MAXN; j+=i)
                            {
                            if (spf[j]==j)
                                spf[j] = i;
                            }
                        }
                    }
                }
                vector<ll> getFactorization(ll x)
                {
                    vector<ll> ret;
                    while (x != 1)
                    {
                        ret.push_back(spf[x]);
                        x = x / spf[x];
                    }
                    return ret;
                }
                ll findGCD(vi v, ll n)
                {
                    ll result = v[0];
                    for (ll i = 1; i < n; i++)
                        result = gcd(v[i], result);

                    return result;
                }
                ll checkPrimeNumber(ll n)
                {
                  bool flag = true;

                  for(ll i = 2; i <= sqrt(n); ++i)
                  {
                      if(n%i == 0)
                      {
                          flag = false;
                          break;
                      }
                  }
                  return flag;
                }
                ll min(ll a,ll b)
                {
                    return a<b?a:b;
                }

            vector<bool> prime(N+1,true);
            void SieveOfEratosthenes()
            {
                prime[0]=false;
                prime[1]=false;
                for (ll p=2; p*p<=N; p++)
                {
                    if(prime[p] == true)
                    {
                      for (ll i=p*p; i<=N; i += p)
                        prime[i] = false;
                    }
                }
            }
            */
               vector<ll> ret;
               vector<ll> getFactorization(ll n)
                {

                    for(ll i=1;i<=sqrt(n);i++)
                        if(n%i==0)
                        {
                            if(i!=n/i) ret.pb(n/i),ret.pb(i);
                            else ret.pb(i);
                        }
                    return ret;

                }
            ll max(ll a,ll b)
            {
                return a>=b?a:b;
            }
            ll modularExponentiation(ll x,ll n,ll mm)
            {
                ll result=1;
                while(n>0)
                {
                    if(n % 2 ==1)
                        result=(result * x)%mm;
                    x=(x*x)%mm;
                    n=n/2;
                }
                return result;
            }
            ll modInverse(ll A,ll mm)
            {
                return modularExponentiation(A,mm-2,mm);
            }
            ll checkPrimeNumber(ll n)
                {
                  bool flag = true;

                  for(ll i = 2; i <= sqrt(n); ++i)
                  {
                      if(n%i == 0)
                      {
                          flag = false;
                          break;
                      }
                  }
                  return flag;
                }
            ll min(ll a,ll b)
            {
                return a>b?b:a;
            }
            bool sortbydiff(pair<ll,ll> &a,pair<ll,ll> &b)
            {
                if(a.fr-a.sc!=b.fr-b.sc)
                    return a.fr-a.sc<b.fr-b.sc;
                else return a.fr<b.fr;
            }
            void solve()
            {
             ll n,p,k;
             cin>>n>>p>>k;
             vi a(n);
             arr(a,n);
             sort(a);
             if(n==2)
             {
                if(a[1]<=p)
                    cout<<2<<endl;
                else if(a[0]<=p)
                    cout<<1<<endl;
                else cout<<0<<endl;
                return;
             }
             vi b(n);
             b[0]=a[0];
             rep(i,1,n) b[i]=b[i-1]+a[i];
             ll ans=0;
             ll j;
             rep(i,0,n)
             {
                if(b[i]<=p)
                    continue;

                    j=i;
                    break;
             }
             rep(i,2,n)
             {
                if(b[i]-a[i-1]<=p)
                {
                    ans=i+1;
                }
             }
             cout<<max(ans,j)<<endl;

            }

            signed main()
            {
                ios_base::sync_with_stdio(false);
                cin.tie(0);
                cout.tie(0);
                #ifndef ONLINE_JUDGE
                 freopen("input.txt","r",stdin);
                 freopen("output.txt","w",stdout);
                #endif
                ll t=1;
                cin>>t;
                while(t--) solve();
            }


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[1000009];
map<ll,ll>d;
map<ll,ll>d1;
int main()
{
    ll w,w1;
    cin>>w;
    for(w1=1; w1<=w; w1++)
    {
    ll n,k,p,i,p1,p2,ans=0;
    cin>>n>>p>>k;
    for(i=1; i<=n; i++)
        cin>>a[i];

    sort(a+1,a+n+1);
    d1[1]=1;
    d[1]=a[1];
    for(i=2; i<=n; i++)
    {
       d[i]=d[i-2]+a[i];
       d1[i]=i;
    }
    for(i=1; i<=n; i++)
    {
        if(d[i]<=p)
        {
            ans=max(ans,d1[i]);
        }
    }
    cout<<ans<<endl;
    }
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    int n,p,k; cin >> n >> p >> k;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    if(a[k-1] > p){
        int cnt = 0;
        ll cost = 0;
        rep(i,n){
            if(p >= cost + a[i]){
                cost += a[i];
                cnt++;
            }else{
                break;
            }
        }
        cout << cnt << "\n";
        return;
    }
    vl sum(n+1,0);
    rep(i,n) sum[i+1] = sum[i] + a[i];
    ll ans = 0;
    REP(i,k,n+1){
        ll cost = a[i-1] + sum[i-k];
        if(cost <= p) chmax(ans, i);
    }
    cout << ans << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    int n,p,k; cin >> n >> p >> k;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    if(a[k-1] > p){
        int cnt = 0;
        ll cost = 0;
        rep(i,n){
            if(p >= cost + a[i]){
                cost += a[i];
                cnt++;
            }else{
                break;
            }
        }
        cout << cnt << "\n";
        return;
    }
    int ok = k, ng = n+1;
    while(ng - ok > 1){
        int mid = (ok + ng) / 2;
        ll cost = 0;
        int last;
        for(int i=mid-1; i>=k-1; i-=k){
            cost += a[i];
            last = i-k;
        }
        rep(i,last+1) cost += a[i];
        if(cost > p) ng = mid;
        else ok = mid;
    }
    cout << ok << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    int n,p,k; cin >> n >> p >> k;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    if(a[k-1] > p){
        int cnt = 0;
        ll cost = 0;
        rep(i,n){
            if(p >= cost + a[i]){
                cost += a[i];
                cnt++;
            }else{
                break;
            }
        }
        cout << cnt << "\n";
        if(cnt != 1) exit(1);
        return;
    }
    int ok = k, ng = n+1;
    while(ng-ok > 1){
        int mid = (ok+ng) / 2;
        ll cost = 0;
        rep(i,mid-k) cost += a[i];
        cost += a[mid-1];
        if(cost > p) ng = mid;
        else ok = mid;
    }
    cout << ok << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    int n,p,k; cin >> n >> p >> k;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    if(a[k-1] > p){
        int cnt = 0;
        ll cost = 0;
        rep(i,n){
            if(p >= cost + a[i]){
                cost += a[i];
                cnt++;
            }else{
                break;
            }
        }
        cout << cnt << "\n";
        return;
    }
    int ok = k, ng = n+1;
    while(ng - ok > 1){
        int mid = (ok + ng) / 2;
        ll cost = 0;
        int last;
        for(int i=mid-1; i>=0; i-=k){
            cost += a[i];
            last = i;
        }
        rep(i,last) cost += a[i];
        if(cost > p) ng = mid;
        else ok = mid;
    }
    cout << ok << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    ll n,p,k; cin >> n >> p >> k;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    if(a[k-1] > p){
        int cnt = 0;
        ll cost = 0;
        rep(i,n){
            if(p >= cost + a[i]){
                cost += a[i];
                cnt++;
            }else{
                break;
            }
        }
        cout << cnt << "\n";
        return;
    }
    int ok = k, ng = n+1;
    while(ng-ok > 1){
        int mid = (ok+ng) / 2;
        ll cost = 0;
        if(mid >= k){
            rep(i,mid-k) cost += a[i];
            cost += a[mid-1];
        }
        if(cost > p) ng = mid;
        else ok = mid;
    }
    cout << ok << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    int n,p,k; cin >> n >> p >> k;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    if(a[k-1] > p){
        int cnt = 0;
        ll cost = 0;
        rep(i,n){
            if(p >= cost + a[i]){
                cost += a[i];
                cnt++;
            }else{
                break;
            }
        }
        cout << cnt << "\n";
        return;
    }
    int ok = k, ng = n+1;
    while(ng-ok > 1){
        int mid = (ok+ng) / 2;
        ll cost = 0;
        rep(i,mid-k) cost += a[i];
        cost += a[mid-1];
        if(cost > p) ng = mid;
        else ok = mid;
    }
    cout << ok << "\n";
}

int main(){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);
    int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}


#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <complex>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 1020000;
ll dy[8] = {0,-1,0,1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
    if(a>b){
        a = b; return true;
    }
    else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
    if(a<b){
        a = b; return true;
    }
    else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
    cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const ll mod = 1e9 + 7;
//const int mod = 998244353;

void solve(){
    int n,p,k; cin >> n >> p >> k;
    vl a(n); rep(i,n) cin >> a[i];
    sort(all(a));
    if(a[k-1] > p){
        int cnt = 0;
        ll cost = 0;
        rep(i,n){
            if(p >= cost + a[i]){
                cost += a[i];
                cnt++;
            }else{
                break;
            }
        }
        cout << cnt << "\n";
        return;
    }
    int ok = k, ng = n+1;
    while(ng-ok > 1){
        int mid = (ok+ng) / 2;
        ll cost = 0;
        rep(i,mid-k) cost += a[i];
        cost += a[mid-1];
        if(cost > p) ng = mid;
        else ok = mid;
    }
    cout << ok << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t = 1;
	cin >> t;
	while(t--){
		solve();
	}
}


#include<bits/stdc++.h>
using namespace std;
int n,p,k;
const int nax=1e5+2,inf=INT_MAX;
int a[nax];
map<pair<int,int>,int> dp;
int solve(int i,int p){
 if(p<0 || i<0)
  return -inf;
 if(p==0 || (i==0 && p>0))
  return 0;
//  cout<<i<<" "<<p<<"\n";
 if(dp[{i,p}]!=0)
  return dp[{i,p}];
 return dp[{i,p}]=max({solve(i-1,p-a[i])+1,solve(i-2,p-a[i])+2,solve(i-1,p)});
}

int main(){
 int t;
 cin>>t;
 while(t--){
  cin>>n>>p>>k;
  dp[{0,0}]=0;
  for(int i=1;i<=n;i++)
   cin>>a[i];
  sort(a,a+n);
  cout<<solve(n,p)<<"\n";
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,p,k;
const int nax=1e5+2,inf=INT_MAX;
int a[nax];
map<pair<int,int>,int> dp;
int solve(int i,int p){
 if(p<0 || i<0)
  return -inf;
 if(p==0 || (i==0 && p>0))
  return 0;
//  cout<<i<<" "<<p<<"\n";
 if(dp[{i,p}]!=0)
  return dp[{i,p}];
 return dp[{i,p}]=max({solve(i-1,p-a[i])+1,solve(i-2,p-a[i])+2,solve(i-1,p)});
}

int main(){
 int t;
 cin>>t;
 while(t--){
  dp.clear();
  cin>>n>>p>>k;
  dp[{0,0}]=0;
  for(int i=1;i<=n;i++)
   cin>>a[i];
  sort(a+1,a+n+1);
  cout<<solve(n,p)<<"\n";
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
 int t;
 cin>>t;
 while(t--){
  int n,p,k;
  cin>>n>>p>>k;
  int a[n];
  for(int i=0;i<n;i++)
   cin>>a[i];
  int c=0;
  int sum,ans=0;
  int pref=0;
  sort(a,a+n);
  for(int i=0;i<=k;i++){
   sum=pref;
   if(sum>=p)
    break;
   c=i;
   for(int j=i+k-1;j<n;j+=k){
    if(sum+a[j]>p)
     break;
    sum+=a[j];
    c+=k;
   }
   pref+=a[i];
   ans=max(ans,c);
  }
  cout<<ans<<"\n";
 }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
 int t;
 cin>>t;
 while(t--){
  int n,p,k;
  cin>>n>>p>>k;
  int a[n];
  for(int i=0;i<n;i++)
   cin>>a[i];
  int c=0;
  int sum,ans=0;
  int pref=0;
  sort(a,a+n);
  for(int i=0;i<k;i++){
   sum=pref;
   if(sum>=p)
    break;
   c=i;
   for(int j=i+k-1;j<n;j+=k){
    if(sum+a[j]>p)
     break;
    sum+=a[j];
    c+=k;
   }
   pref+=a[i];
   ans=max(ans,c);
  }
  cout<<ans<<"\n";
 }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
 int t;
 cin>>t;
 while(t--){
  int n,p,k;
  cin>>n>>p>>k;
  int a[n];
  for(int i=0;i<n;i++)
   cin>>a[i];
  int c=0;
  int sum,ans=0;
  int pref=0;
  for(int i=0;i<k;i++){
   sum=pref;
   if(sum>=p)
    break;
   c=i;
   for(int j=i+k-1;j<n;j+=k){
    if(sum+a[j]>p)
     break;
    sum+=a[j];
    c+=k;
   }
   pref+=a[i];
   ans=max(ans,c);
  }
  cout<<ans<<"\n";
 }
}


#include<bits/stdc++.h>
using namespace std;
int n,p,k;
const int nax=1e5+2,inf=INT_MAX;
int a[nax];
map<pair<int,int>,int> dp;
int solve(int i,int p){
 if(p<0 || i<0)
  return -inf;
 if(p==0 || (i==0 && p>0))
  return 0;
//  cout<<i<<" "<<p<<"\n";
 if(dp[{i,p}]!=0)
  return dp[{i,p}];
 return dp[{i,p}]=max({solve(i-1,p-a[i])+1,solve(i-2,p-a[i])+2,solve(i-1,p)});
}

int main(){
 int t;
 cin>>t;
 while(t--){
  dp.clear();
  cin>>n>>p>>k;
  dp[{0,0}]=0;
  for(int i=1;i<=n;i++)
   cin>>a[i];
  sort(a,a+n);
  cout<<solve(n,p)<<"\n";
 }
 return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
 int t;
 cin>>t;
 while(t--){
  int n,p,k;
  cin>>n>>p>>k;
  int a[n];
  for(int i=0;i<n;i++)
   cin>>a[i];
  int c=0;
  int sum,ans=0;
  int pref=0;
  sort(a,a+n);
  for(int i=0;i<=k;i++){
   sum=pref;
   if(sum>p)
    break;
   c=i;
   for(int j=i+k-1;j<n;j+=k){
    if(sum+a[j]>p)
     break;
    sum+=a[j];
    c+=k;
   }
   pref+=a[i];
   ans=max(ans,c);
  }
  cout<<ans<<"\n";
 }
}


#include<bits/stdc++.h>
using namespace std;
int n,p,k;
const int nax=1e5+2,inf=INT_MAX;
int a[nax];
int dp[nax];
int vis[nax];
int solve(int i,int p){
 if(p<0 || i<0)
  return -inf;
 if(p==0 || (i==0 && p>0))
  return 0;
//  cout<<i<<" "<<p<<"\n";
 if(vis[i]>3)
  return dp[i];
 vis[i]++;
 return dp[i]=max({solve(i-1,p-a[i])+1,solve(i-2,p-a[i])+2,solve(i-1,p)});
}

int main(){
 int t;
 cin>>t;
 while(t--){
  cin>>n>>p>>k;
  memset(dp,-1,sizeof(dp));
  memset(vis,0,sizeof(vis));
  for(int i=1;i<=n;i++)
   cin>>a[i];
  sort(a+1,a+n+1);
  cout<<solve(n,p)<<"\n";
 }
 return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int j=0;
        while(j<n){
            if(j+1<n&&v[j+1]<=k){
                m+=2;
                k-=v[j+1];
                j+=2;
            }else if(v[j]<=k){
                k-=v[j];
                ++m;
                ++j;
            }else{
                break;
            }
        }

        while(n>1&&c>=v[1]){
            if(n<3){
                if(n==2&&c>=v[1]){
                    c-=v[1];
                    ans+=2;
                    n-=2;
                    v.clear();
                }else{
                    if(c>=v[0]){
                        ++ans;
                        c-=v[0];
                    }
                    //v.clear();
                    n-=1;
                    v.erase(v.begin());

                }
            }else{
                if(v[0]+v[2]<=c){
                    c-=v[0]+v[2];
                    v.erase(v.begin(),v.begin()+3);
                    n-=3;
                    ans+=3;
                }else{
                    if(v[1]<=c){
                        c-=v[1];
                        ans+=2;
                        v.erase(v.begin(),v.begin()+2);
                        n-=2;
                    }
                }

            }
        }
        if(n>0&&c>=v[0])++ans;

        c=k;
        ans=max(ans,m);
        cout<<ans<<endl;

    }

	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int j=0;
        while(j<n){
            if(j+1<n&&v[j+1]<=k){
                m+=2;
                k-=v[j+1];
                j+=2;
            }else if(v[j]<=k){
                k-=v[j];
                ++m;
                ++j;
            }else{
                break;
            }
        }

        while(n>1&&c>=v[1]){
            if(n<3){
                if(n==2&&c>=v[1]){
                    c-=v[1];
                    ans+=2;
                    n-=2;
                    v.clear();
                }else{
                    if(c>=v[0]){
                        ++ans;
                        c-=v[0];
                    }
                    //v.clear();
                    n-=1;
                    v.erase(v.begin());

                }
            }else{
                if(n>=4){
                    if(v[1]+v[3]>=c){
                        c-=v[1]+v[3];
                        ans+=4;
                        v.erase(v.begin(),v.begin()+4);
                        n-=4;
                        continue;
                    }
                }
                if(v[0]+v[2]<=c){
                    c-=v[2]+v[0];
                    v.erase(v.begin(),v.begin()+3);
                    n-=3;
                    ans+=3;
                }else{
                    if(c>=v[1]){
                        c-=v[1];
                        v.erase(v.begin(),v.begin()+2);
                        n-=2;
                        ans+=2;
                    }

                }
            }
        }
        if(n>0&&c>=v[0])++ans;

        c=k;
        ans=max(ans,m);
        cout<<ans<<endl;

    }

	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int j=0;
        while(j<n){
            if(j+1<n&&v[j+1]<=k){
                m+=2;
                k-=v[j+1];
                j+=2;
            }else if(v[j]<=k){
                k-=v[j];
                ++m;
                ++j;
            }else{
                break;
            }
        }

        while(n>1&&c>=v[1]){
//            if(n<3){
//                if(n==2&&c>=v[1]){
//                    c-=v[1];
//                    ans+=2;
//                    n-=2;
//                    v.clear();
//                }else{
//                    if(c>=v[0]){
//                        ++ans;
//                        c-=v[0];
//                    }
//                    //v.clear();
//                    n-=1;
//                    v.erase(v.begin());
//
//                }
            //}else{
                if(n>=3&&v[0]+v[2]<=c){
                    c-=v[0]+v[2];
                    v.erase(v.begin(),v.begin()+3);
                    n-=3;
                    ans+=3;
                }else{
                    if(n>=1&&v[1]<=c){
                        c-=v[1];
                        ans+=2;
                        v.erase(v.begin(),v.begin()+2);
                        n-=2;
                    }
                }

            //}
        }
        if(n>0&&c>=v[0])++ans;

        c=k;
        ans=max(ans,m);
        cout<<ans<<endl;

    }

	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int j=0;
        while(j<n-1){
            if(v[j+1]<=k){
                m+=2;
                k-=v[j+1];
                j+=2;
            }else if(v[j]<=k){
                k-=v[j];
                ++m;
                ++j;
            }else{
                break;
            }
        }

        while(n>1&&c>=v[1]){
            if(n<3){
                if(n==2&&c>=v[1]){
                    c-=v[1];
                    ans+=2;
                    n-=2;
                    v.clear();
                }else{
                    if(c>=v[0]){
                        ++ans;
                        c-=v[0];
                    }
                    //v.clear();
                    n-=1;
                    v.erase(v.begin());

                }
            }else{
                if(v[0]+v[2]<=c){
                    c-=v[2]+v[0];
                    v.erase(v.begin(),v.begin()+3);
                    n-=3;
                    ans+=3;
                }else{
                    if(c>=v[1]){
                        c-=v[1];
                        v.erase(v.begin(),v.begin()+2);
                        n-=2;
                        ans+=2;
                    }

                }
            }
        }
        if(n>0&&c>=v[0])++ans;

        c=k;
        ans=max(ans,m);
        cout<<ans<<endl;

    }

	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int j=0;
        while(j<n){
            if(j+1<n&&v[j+1]<=k){
                m+=2;
                k-=v[j+1];
                j+=2;
            }else if(v[j]<=k){
                k-=v[j];
                ++m;
                ++j;
            }else{
                break;
            }
        }

        while(n>1&&c>=v[1]){
            if(n<3){
                if(n==2&&c>=v[1]){
                    c-=v[1];
                    ans+=2;
                    n-=2;
                    v.clear();
                }else{
                    if(c>=v[0]){
                        ++ans;
                        c-=v[0];
                    }
                    //v.clear();
                    n-=1;
                    v.erase(v.begin());

                }
            }else{
                if(n>=4){
                    if(v[1]+v[3]<=c){
                        c-=v[1]+v[3];
                        ans+=4;
                        v.erase(v.begin(),v.begin()+4);
                        n-=4;
                        continue;
                    }
                }
                if(v[0]+v[2]<=c){
                    c-=v[2]+v[0];
                    v.erase(v.begin(),v.begin()+3);
                    n-=3;
                    ans+=3;
                }else{
                    if(c>=v[1]){
                        c-=v[1];
                        v.erase(v.begin(),v.begin()+2);
                        n-=2;
                        ans+=2;
                    }

                }
            }
        }
        if(n>0&&c>=v[0])++ans;

        c=k;
        ans=max(ans,m);
        cout<<ans<<endl;

    }

	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int j=0;
        while(j<n-1){
            if(v[j+1]<=k){
                m+=2;
                k-=v[j+1];
                j+=2;
            }else if(v[j]<=k){
                k-=v[j];
                ++m;
                ++j;
            }else{
                break;
            }
        }

        while(n>1&&c>=v[1]){
            if(n<3){
                if(n==2&&c>=v[1]){
                    c-=v[1];
                    ans+=2;
                    n-=2;
                    v.clear();
                }else{
                    if(c>=v[0]){
                        ++ans;
                        c-=v[0];
                    }
                    //v.clear();
                    n-=1;
                    v.erase(v.begin());

                }
            }else{
                if(v[0]+v[2]<=c){
                    c-=v[2]+v[0];
                    v.erase(v.begin(),v.begin()+3);
                    n-=3;
                    ans+=3;
                }else{
                    if(c>=v[1]){
                        c-=v[1];
                        v.erase(v.begin(),v.begin()+2);
                        n-=2;
                        ans+=2;
                    }

                }
            }
        }
        if(n>0&&c>=v[0])++ans;

        c=k;
        ans=max(ans,m);
        cout<<ans<<endl;

    }

	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{1};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int j=0;
        while(j<n){
            if(j+1<n&&v[j+1]<=k){
                m+=2;
                k-=v[j+1];
                j+=2;
            }else if(v[j]<=k){
                k-=v[j];
                ++m;
                ++j;
            }else{
                break;
            }
        }

        while(n>1&&c>=v[1]){
            if(n<3){
                if(n==2&&c>=v[1]){
                    c-=v[1];
                    ans+=2;
                    n-=2;
                    v.clear();
                }else{
                    if(c>=v[0]){
                        ++ans;
                        c-=v[0];
                    }
                    //v.clear();
                    n-=1;
                    v.erase(v.begin());

                }
            }else{
                if(v[0]+v[2]<=c){
                    c-=v[2]+v[0];
                    v.erase(v.begin(),v.begin()+3);
                    n-=3;
                    ans+=3;
                }else{
                    if(c>=v[1]){
                        c-=v[1];
                        v.erase(v.begin(),v.begin()+2);
                        n-=2;
                        ans+=2;
                    }

                }
            }
        }
        if(n>0&&c>=v[0])++ans;

        c=k;
        ans=max(ans,m);
        cout<<ans<<endl;

    }

	return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<cstring>
#include<math.h>
#include<iomanip>
#include<vector>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<cctype>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<iterator>
#include<limits>
#include<map>
#include<deque>
using namespace std;
#define pb push_back
#define F(i,a,b) for(int i=a;i<b;++i)
#define Fl(i,a,b) for(long long i=a;i<b;++i)
#define all(v) v.begin(), v.end()
#define X first
#define Y second
#define mp make_pair
typedef long long ll;
typedef std::vector<int> vec;
typedef std::vector<long long> vecl;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef std::pair<int,int> pii;
typedef pair<ll,ll> pll;
const int MOD = 1000000007;
#define pie 3.141592653589793238462643383279

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

 	int t{},T{};
 	cin>>t;T=t;
    //t=1;
 	while(t--){
        //cout<<"------------- #"<<T-t<<endl;
        int n{},m{},ans{},k{},a{},b{},c{},f{0};
        cin>>n>>c>>k;
        k=c;
        vec v(n);
        F(i,0,n)cin>>v[i];
        sort(all(v));
        int dp[n]{};
        dp[0]=v[0];
        F(i,1,n){
            a=dp[i-1]+v[i];
            if(i>=2){
                b=dp[i-2]+v[i];
                dp[i]=min(a,b);

            }else{
                dp[i]=min(a,v[i]);
            }
        }
        F(i,0,n){
            if(dp[i]>c){
                ans=i;
                break;
            }else{
                f=1;
            }
        }

        if(f){
            if(ans==0)ans=n;
            cout<<ans<<endl;
        }else{
            cout<<0<<endl;
        }

    }

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#include <string>
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll t;
  cin>>t;
  int a[20000];
  while (t--) {
    ll n,k,p;
    cin>>n;
    cin>>p;
    cin>>k;
    ll n0=n;
    ll p0=p;

    ll nn=0;
    for (int i=0;i<n;i++)cin>>a[i];
    std::sort (a,a+n);
    for (int i=0;i<n;i++){
      if(a[i]<=2*a[i+1] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    ll nn1=nn;
    p=p0;

    nn=0;
    if(p>0)p-=a[0];
    if(p>=0)nn++;
    for (int i=1;i<n;i++){
      if(a[i]<=2*a[i+1] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    nn=max(nn1,nn);
    cout<<nn<<endl;

    //    cout<<x<<endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
#include <string>
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll t;
  cin>>t;
  int a[200000];
  while (t--) {
    ll n,k,p;
    cin>>n;
    cin>>p;
    cin>>k;
    ll n0=n;
    ll p0=p;

    ll nn=0;
    for (int i=0;i<n;i++)cin>>a[i];
    std::sort (a,a+n);
    for (int i=0;i<n;i++){
      if(a[i+1]<=2*a[i] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    ll nn1=nn;
    p=p0;

    nn=0;
    if(p>0)p-=a[0];
    if(p>=0)nn++;
    for (int i=1;i<n;i++){
      if(a[i+1]<=2*a[i] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    nn=max(nn1,nn);
    cout<<nn<<endl;

    //    cout<<x<<endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
#include <string>
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll t;
  cin>>t;
  int a[20000];
  while (t--) {
    int n,k,p;
    cin>>n;
    cin>>p;
    cin>>k;
    int n0=n;
    int p0=p;

    int nn=0;
    for (int i=0;i<n;i++)cin>>a[i];
    std::sort (a,a+n);
    for (int i=0;i<n;i++){
      if(a[i]<=2*a[i+1] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    int nn1=nn;
    p=p0;

    nn=0;
    if(p>0)p-=a[0];
    if(p>=0)nn++;
    for (int i=1;i<n;i++){
      if(a[i]<=2*a[i+1] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    nn=max(nn1,nn);
    cout<<nn<<endl;

    //    cout<<x<<endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
#include <string>
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll t;
  cin>>t;
  int a[200005];
  while (t--) {
    ll n,k,p;
    cin>>n;
    cin>>p;
    cin>>k;
    ll n0=n;
    ll p0=p;

    ll nn=0;
    for (int i=0;i<n;i++)cin>>a[i];
    a[n]=0;
    std::sort (a,a+n);
    for (int i=0;i<n;i++){
      if(a[i+1]<2*a[i] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    ll nn1=nn;
    p=p0;

    nn=0;
    if(p>0)p-=a[0];
    if(p>=0)nn++;
    for (int i=1;i<n;i++){
      if(a[i+1]<2*a[i] and i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    nn=max(nn1,nn);
    cout<<nn<<endl;

    //    cout<<x<<endl;
  }

}


#include <bits/stdc++.h>
using namespace std;
#include <string>
typedef long long ll;

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  ll t;
  cin>>t;
  int a[200001];
  while (t--) {
    ll n,k,p;
    cin>>n;
    cin>>p;
    cin>>k;
    ll n0=n;
    ll p0=p;

    ll nn=0;
    for (int i=0;i<n;i++)cin>>a[i];
    std::sort (a,a+n);
    for (int i=0;i<n;i++){
      if(i+1<n){
	p-=a[i+1];
	if(p>=0){
	  //cout<<a[i]<<" GG "<<a[i+1]<<" "<<i<<endl;
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    ll nn1=nn;
    p=p0;

    nn=0;
    if(p>0)p-=a[0];
    if(p>=0)nn++;
    for (int i=1;i<n;i++){
      if(i+1<n){
	p-=a[i+1];
	if(p>=0){
	  nn+=2;
	  i++;
	}else{
	  if(p>=a[i]){
	    p-=a[i];
	    if(p>=0)nn++;
	  }
	}
      }else{
	p-=a[i];
	if(p>=0)nn++;
      }
      if(p<=0)break;
      if(nn>=n)break;
    }
    nn=max(nn1,nn);
    cout<<nn<<endl;

    //    cout<<x<<endl;
  }

}


#include<bits/stdc++.h>
using namespace std;
int arr[100001];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        for(int i=1; i<=n; i++)cin>>arr[i];
        sort(arr+1,arr+1+n);
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(p<=0)break;
            int cnt = i-1;
            int currSum = p;
            for(int j=i+k-1; j<=n; j+=k)
            {
                if(currSum-arr[j]>=0)
                {
                    currSum-=arr[j];
                    cnt+=k;
                }
                else break;
            }
            p-=arr[i];
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int arr[300001];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        for(int i=1; i<=n; i++)cin>>arr[i];
        sort(arr+1,arr+1+n);
        int ans=0;
        for(int i=1; i<=k; i++)
        {
            if(p<0)break;
            int cnt = i-1;
            int currSum = p;
            for(int j=i+k-1; j<=n; j+=k)
            {
                if(currSum-arr[j]>=0)
                {
                    currSum-=arr[j];
                    cnt+=k;
                }
                else break;
            }
            //if(cnt == i-1 && i-1>1)break;
            p-=arr[i];
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int arr[300001];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        for(int i=1; i<=n; i++)cin>>arr[i];
        sort(arr+1,arr+1+n);
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(p<0)break;
            int cnt = i-1;
            int currSum = p;
            for(int j=i+k-1; j<=n; j+=k)
            {
                if(currSum-arr[j]>=0)
                {
                    currSum-=arr[j];
                    cnt+=k;
                }
                else break;
            }
            //if(cnt == i-1 && i-1>1)break;
            p-=arr[i];
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int cum[300001];
int arr[300001];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        cum[0] = 0;
        for(int i=1; i<=n; i++)
        {
            cin>>arr[i];
        }
        sort(arr+1,arr+1+n);
        for(int i=1; i<=n; i++)
        {
            cum[i]=cum[i-1]+arr[i];
        }
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(i-k>=0)
            {
                cum[i]=min(cum[i],cum[i-k]+arr[i]);
            }
            if(cum[i]<=p)ans=i;
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int arr[300001];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        for(int i=1; i<=n; i++)cin>>arr[i];
        sort(arr+1,arr+1+n);
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(p<0)break;
            int cnt = i-1;
            int currSum = p;
            for(int j=i+k-1; j<=n; j+=k)
            {
                if(currSum-arr[j]>=0)
                {
                    currSum-=arr[j];
                    cnt+=k;
                }
                else break;
            }
            if(cnt == i-1)break;
            p-=arr[i];
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int arr[100001];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        for(int i=1; i<=n; i++)cin>>arr[i];
        sort(arr+1,arr+1+n);
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(p<0)break;
            int cnt = i-1;
            int currSum = p;
            for(int j=i+k-1; j<=n; j+=k)
            {
                if(currSum-arr[j]>=0)
                {
                    currSum-=arr[j];
                    cnt+=k;
                }
                else break;
            }
            p-=arr[i];
            ans=max(ans,cnt);
        }
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int tree[4*100001];
int arr[100001];
void build(int idx, int l, int r)
{
    if(l==r)
    {
        tree[idx]=arr[l];
        return;
    }
    int mid = (l+r)/2;
    int lft = idx*2;
    int rgt = lft +1;
    build(lft,l,mid);
    build(rgt,mid+1,r);
    tree[idx] = max(tree[lft],tree[rgt]);
}
int query(int idx,int l,int r,int L,int R)
{
    if(R<l || L>r)return 0;
    if(L<=l && r<=R)return tree[idx];
    int mid = (l+r)/2;
    int lft = idx*2;
    int rgt = lft +1;
    int p1 = query(lft,l,mid,L,R);
    int p2 = query(rgt,mid+1,r,L,R);
    return max(p1,p2);
}
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        for(int i=1; i<=n; i++)
        {
            cin>>arr[i];
        }
        sort(arr+1,arr+1+n);
        build(1,1,n);
        int cnt=0;
        for(int i=1; i<=n; i++)
        {
            if(p-arr[i]>=0)
            {
                if(p-arr[i]<arr[i+1] && i+1<=n)
                {
                    int l = i;
                    int r = i+k-1;
                    int mx = query(1,1,n,l,r);
                    //cout<<l<<" "<<r<<" "<<mx<<endl;
                    if(p-mx<0)
                    {
                        p-=arr[i];
                        cnt++;
                    }
                    else
                    {
                        p-=mx;
                        i+=k-1;
                        cnt+=k;
                    }
                }
                else
                {
                    p-=arr[i];
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int tree[4*100001];
int arr[100001];
void build(int idx, int l, int r)
{
    if(l==r)
    {
        tree[idx]=arr[l];
        return;
    }
    int mid = (l+r)/2;
    int lft = idx*2;
    int rgt = lft +1;
    build(lft,l,mid);
    build(rgt,mid+1,r);
    tree[idx] = max(tree[lft],tree[rgt]);
}
int query(int idx,int l,int r,int L,int R)
{
    if(R<l || L>r)return 0;
    if(L<=l && r<=R)return tree[idx];
    int mid = (l+r)/2;
    int lft = idx*2;
    int rgt = lft +1;
    int p1 = query(lft,l,mid,L,R);
    int p2 = query(rgt,mid+1,r,L,R);
    return max(p1,p2);
}
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        for(int i=1; i<=n; i++)
        {
            cin>>arr[i];
        }
        sort(arr+1,arr+1+n);
        build(1,1,n);
        int cnt=0;
        for(int i=1; i<=n; i++)
        {
            if(p-arr[i]>=0)
            {
                if(p-arr[i]<arr[i+1] && i+1<=n)
                {
                    int l = i;
                    int r = i+k-1;
                    int mx = query(1,1,n,l,r);
                    //cout<<l<<" "<<r<<" "<<mx<<endl;
                    if(p-mx<0)
                    {
                        p-=arr[i];
                        cnt++;
                    }
                    else
                    {
                        p-=mx;
                        i+=k;
                        cnt+=k;
                    }
                }
                else
                {
                    p-=arr[i];
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int cum[300001];
int arr[300001];
int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        cum[0] = 0;
        for(int i=1; i<=n; i++)
        {
            cin>>arr[i];
        }
        for(int i=1; i<=n; i++)
        {
            cum[i]=cum[i-1]+arr[i];
        }
        int ans=0;
        for(int i=1; i<=n; i++)
        {
            if(i-k>=0)
            {
                cum[i]=min(cum[i],cum[i-k]+arr[i]);
            }
            if(cum[i]<=p)ans=i;
        }
        cout<<ans<<endl;
    }
}


#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

vector<int> v;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t; cin >> t;
        while (t--) {
                v.clear();
                int n, m, k, i; cin >> n >> m >> k;
                k = 2;
                for (i = 0; i < n; i++) {
                        int a; cin >> a;
                        v.push_back(a);
                }
                sort(v.begin(), v.end());
                if (k >= n) {
                        i = n;
                        while (i && m < v[i - 1]) i -= 1;
                        cout << i << endl;
                        continue;
                }
                ll s = 0;
                for (i = k; i < n && s <= m; i++) s += v[i];
                if (s > m) {
                        i -= 1;
                        s -= v[i];
                        while (i && m < v[i - 1]) i -= 1;
                }
                cout << i << endl;
        }
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t; cin >> t;
        while (t--) {
                v.clear();
                int n, m, k, i; cin >> n >> m >> k;
                k = 2;
                for (i = 0; i < n; i++) {
                        int a; cin >> a;
                        v.push_back(a);
                }
                sort(v.begin(), v.end());
                if (k >= n) {
                        i = n;
                        while (i && m < v[i - 1]) i -= 1;
                        cout << i << endl;
                        continue;
                }
                int s = 0;
                for (i = k; i < n && s <= m; i++) s += v[i];
                if (s > m) {
                        i -= 1;
                        s -= v[i];
                        while (i && m < v[i - 1]) i -= 1;
                }
                cout << i << endl;
        }
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int n, k;
ll m;
vector<ll> v;

ll is(int a) {
        ll s = 0;
        int i;
        for (i = a; i < n; i += k) {
                s += v[i];
                if (s > m) break;
        }
        if (i < n) s -= v[i];
        int j;
        for (j = min(i - 1, n - 1); j > i - k; j--) {
                s += v[j];
                if (s <= m) break;
                s -= v[j];
        }
        return j + 1;
}

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t; cin >> t;
        while (t--) {
                v.clear();
                cin >> n >> m >> k;
                k = 2;
                for (int i = 0; i < n; i++) {
                        ll a; cin >> a;
                        v.push_back(a);
                }
                sort(v.begin(), v.end());
                cout << max(is(0), is(1)) << endl;
        }
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

vector<ll> v;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t; cin >> t;
        while (t--) {
                v.clear();
                int n, k, i;
                ll m; cin >> n >> m >> k;
                k = 2;
                for (i = 0; i < n; i++) {
                        ll a; cin >> a;
                        v.push_back(a);
                }
                sort(v.begin(), v.end());
                ll s = 0, aaa = 0, bbb = 0;
                for (i = 0; i < n; i += k) {
                        s += v[i];
                        if (s > m) break;
                }
                s -= v[i];
                int j;
                for (j = min(i - 1, n - 1); j > i - k; j--) {
                        s += v[j];
                        if (s <= m) break;
                        s -= v[j];
                }
                aaa = j + 1;

                s = 0;
                for (i = 1; i < n; i += k) {
                        s += v[i];
                        if (s > m) break;
                }
                s -= v[i];
                for (j = min(i - 1, n - 1); j > i - k; j--) {
                        s += v[j];
                        if (s <= m) break;
                        s -= v[j];
                }
                bbb = j + 1;
                cout << max(aaa, bbb) << endl;
        }
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int n, k;
ll m;
vector<ll> v;

ll is(int a) {
        ll s = 0;
        int i;
        for (i = a; i < n; i += k) {
                s += v[i];
                if (s > m) break;
        }
        s -= v[i];
        int j;
        for (j = min(i - 1, n - 1); j > i - k; j--) {
                s += v[j];
                if (s <= m) break;
                s -= v[j];
        }
        return j + 1;
}

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t; cin >> t;
        while (t--) {
                v.clear();
                cin >> n >> m >> k;
                k = 2;
                for (int i = 0; i < n; i++) {
                        ll a; cin >> a;
                        v.push_back(a);
                }
                sort(v.begin(), v.end());
                cout << max(is(0), is(1)) << endl;
        }
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t; cin >> t;
        while (t--) {
                v.clear();
                int n, m, k, i; cin >> n >> m >> k;
                for (i = 0; i < n; i++) {
                        int a; cin >> a;
                        v.push_back(a);
                }
                sort(v.begin(), v.end());
                if (k >= n) {
                        i = n;
                        while (i && m < v[i - 1]) i -= 1;
                        cout << i << endl;
                        continue;
                }
                int s = 0;
                for (i = k; i < n && s <= m; i++) s += v[i];
                if (s > m) {
                        i -= 1;
                        s -= v[i];
                        while (i && m < v[i - 1]) i -= 1;
                }
                cout << i << endl;
        }
        return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

vector<ll> v;

int main() {
        ios::sync_with_stdio(0);
        cin.tie(0);
        int t; cin >> t;
        while (t--) {
                v.clear();
                int n, k, i;
                ll m; cin >> n >> m >> k;
                k = 2;
                for (i = 0; i < n; i++) {
                        ll a; cin >> a;
                        v.push_back(a);
                }
                sort(v.begin(), v.end());
                if (k >= n) {
                        i = n;
                        while (i && m < v[i - 1]) i -= 1;
                        cout << i << endl;
                        continue;
                }
                ll s = 0;
                for (i = k; i < n && s <= m; i++) s += v[i];
                if (s > m) {
                        i -= 1;
                        s -= v[i];
                        while (i && m < v[i - 1]) i -= 1;
                }
                cout << i << endl;
        }
        return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll> m;
map<ll,ll> :: iterator it;
int main(){
     ll test,n,i,coin,k,a[200001],ans,s;
     cin>>test;
     while(test--){
          ans=0;
          cin>>n>>coin>>k;
          for(i=1; i<=n; i++){
               cin>>a[i];
          }
          sort(a+1,a+n+1);
          if(n%2==0){
               if(a[2]<=coin && n==2){
                    cout<<2;
               }
               else{
                    if(a[1]<=coin && n==2){
                         cout<<1;
                    }
                    else{
                         ll s1,s2,x=0;
                         ans=0;
                         for( i=2; i<=n; i=i+2){
                              if(ans+a[i]<=coin) ans+=a[i];
                              else {x=1;break;}
                         }
                         if(x==0){
                         s1=n;
                         }
                         else{
                              if(a[i-1]+ans<=coin){
                              s1=i-1;
                              }
                              else s1=i-2;
                         }
                         ans=0;
                         x=0;
                         if(a[1]>coin) s2=0;
                         else{
                              for(int i=3; i<=n; i=i+2){
                                   if(ans+a[i]<=coin) ans+=a[i];
                                   else {x=1;break;}
                              }
                              if(x=0){
                                   s2=n;
                              }
                              if(ans+a[i-1]<=coin) s2=i-1;
                              else s2=i-2;
                         }
                         cout<<max(s1,s2);
                    }
               }
          }
          else{
               ans=0;
               int x=0;
               if(a[1]>coin){
                    cout<<0;
               }
               else{
                    ll s,s1;
                    ans+=a[1];
                    for(i=3; i<=n; i=i+2){
                         if(ans+a[i]<=coin) {ans+=a[i];}
                         else {x=1;break;}
                    }
                    if(x==0){
                         s=n;
                    }
                    else{
                         if(ans+a[i-1]<=coin){
                              s=i-1;
                         }
                         else s=i-2;
                    }
                    x=0;
                    ans=0;
                    for(int i=2; i<=n; i=i+2){
                         if(ans+a[i]<=coin) ans+=a[i];
                         else{x=1;break;}
                    }
                    if(x==0){
                         if(ans+a[n]<=coin) s1=n;
                         else s1=n-1;
                    }
                    else{
                         if(ans+a[i-1]<coin) s1=i-1;
                         else s1=i-2;
                    }
                    cout<<max(s1,s);
               }

          }
          cout<<endl;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll> m;
map<ll,ll> :: iterator it;
int main(){
     ll test,n,i,coin,k,a[200001],ans,s;
     cin>>test;
     while(test--){
          ans=0;
          cin>>n>>coin>>k;
          for(i=1; i<=n; i++){
               cin>>a[i];
          }
          sort(a+1,a+n+1);
          if(n%2==0){
               if(a[2]<=coin && n==2){
                    cout<<2;
               }
               else{
                    if(a[1]<=coin && n==2){
                         cout<<1;
                    }
                    else{
                         ll s1,s2,x=0;
                         ans=0;
                         for(i=2; i<=n; i=i+2){
                              if(ans+a[i]<=coin) ans+=a[i];
                              else {x=1;break;}
                         }
                         if(x==0){
                         s1=n;
                         }
                         else{
                              if(a[i-1]+ans<=coin){
                              s1=i-1;
                              }
                              else s1=i-2;
                         }
                         ans=0;
                         x=0;
                         if(a[1]>coin) s2=0;
                         else{
                              ans+=a[1];
                              for(int i=3; i<=n; i=i+2){
                                   if(ans+a[i]<=coin) ans+=a[i];
                                   else {x=1;break;}
                              }
                              if(x=0){
                                   if(ans+a[n]<=coin) s2=n;
                                   else s2=n-1;
                              }
                              if(ans+a[i-1]<=coin) s2=i-1;
                              else s2=i-2;
                         }
                         cout<<max(s1,s2);
                    }
               }
          }
          else{
               ans=0;
               int x=0;
               if(a[1]>coin){
                    cout<<0;
               }
               else{
                    ll s,s1;
                    ans+=a[1];
                    for(i=3; i<=n; i=i+2){
                         if(ans+a[i]<=coin) {ans+=a[i];}
                         else {x=1;break;}
                    }
                    if(x==0){
                         s=n;
                    }
                    else{
                         if(ans+a[i-1]<=coin){
                              s=i-1;
                         }
                         else s=i-2;
                    }
                    x=0;
                    ans=0;
                    for(int i=2; i<=n; i=i+2){
                         if(ans+a[i]<=coin) ans+=a[i];
                         else{x=1;break;}
                    }
                    if(x==0){
                         if(ans+a[n]<=coin) s1=n;
                         else s1=n-1;
                    }
                    else{
                         if(ans+a[i-1]<=coin) s1=i-1;
                         else s1=i-2;
                    }
                    cout<<max(s1,s);
               }

          }
          cout<<endl;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll> m;
map<ll,ll> :: iterator it;
int main(){
     ll test,n,i,coin,k,a[200001],ans,s;
     cin>>test;
     while(test--){
          ans=0;
          cin>>n>>coin>>k;
          for(i=1; i<=n; i++){
               cin>>a[i];
          }
          sort(a+1,a+n+1);
          if(n%2==0){
               if(a[2]<=coin && n==2){
                    cout<<2;
               }
               else{
                    if(a[1]<=coin && n==2){
                         cout<<1;
                    }
                    else{
                         ll s1,s2,x=0;
                         ans=0;
                         for( i=2; i<=n; i=i+2){
                              if(ans+a[i]<=coin) ans+=a[i];
                              else {x=1;break;}
                         }
                         if(x==0){
                         s1=n;
                         }
                         else{
                              if(a[i-1]+ans<=coin){
                              s1=i-1;
                              }
                              else s1=i-2;
                         }
                         ans=0;
                         x=0;
                         if(a[1]>coin) s2=0;
                         else{
                              for(int i=3; i<=n; i=i+2){
                                   if(ans+a[i]<=coin) ans+=a[i];
                                   else {x=1;break;}
                              }
                              if(x=0){
                                   if(ans+a[n]<=coin) s2=n;
                                   else s2=n-1;
                              }
                              if(ans+a[i-1]<=coin) s2=i-1;
                              else s2=i-2;
                         }
                         cout<<max(s1,s2);
                    }
               }
          }
          else{
               ans=0;
               int x=0;
               if(a[1]>coin){
                    cout<<0;
               }
               else{
                    ll s,s1;
                    ans+=a[1];
                    for(i=3; i<=n; i=i+2){
                         if(ans+a[i]<=coin) {ans+=a[i];}
                         else {x=1;break;}
                    }
                    if(x==0){
                         s=n;
                    }
                    else{
                         if(ans+a[i-1]<=coin){
                              s=i-1;
                         }
                         else s=i-2;
                    }
                    x=0;
                    ans=0;
                    for(int i=2; i<=n; i=i+2){
                         if(ans+a[i]<=coin) ans+=a[i];
                         else{x=1;break;}
                    }
                    if(x==0){
                         if(ans+a[n]<=coin) s1=n;
                         else s1=n-1;
                    }
                    else{
                         if(ans+a[i-1]<coin) s1=i-1;
                         else s1=i-2;
                    }
                    cout<<max(s1,s);
               }

          }
          cout<<endl;
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll> m;
map<ll,ll> :: iterator it;
int main(){
     ll test,n,i,coin,k,a[200001],ans,s;
     cin>>test;
     while(test--){
          ans=0;
          cin>>n>>coin>>k;
          for(i=1; i<=n; i++){
               cin>>a[i];
          }
          sort(a+1,a+n+1);
          if(n%2==0){
               for( i=2; i<=n; i=i+2){
                    if(ans+a[i]<=coin) ans+=a[i];
                    else break;
               }
               if(i==n+1){
                    cout<<n;
               }
               else{
                    if(a[i-1]+ans<=coin){
                         cout<<i-1;
                    }
                    else cout<<i-2;
               }
          }
          else{
               ans=0;
               int x=0;
               if(a[1]>coin){
                    cout<<0;
               }
               else{
                    ll s,s1;
                    ans+=a[1];
                    for(i=3; i<=n; i=i+2){
                         if(ans+a[i]<=coin) {ans+=a[i];}
                         else {x=1;break;}
                    }
                    if(x==0){
                         s=n;
                    }
                    else{
                         if(ans+a[i-1]<=coin){
                              s=i-1;
                         }
                         else s=i-2;
                    }
                    x=0;
                    ans=0;
                    for(int i=2; i<=n; i=i+2){
                         if(ans+a[i]<=coin) ans+=a[i];
                         else{x=1;break;}
                    }
                    if(x==0){
                         if(ans+a[n]<=coin) s1=n;
                         else s1=n-1;
                    }
                    else{
                         if(ans+a[i-1]<coin) s1=i-1;
                         else s1=i-2;
                    }
                    cout<<max(s1,s);
               }

          }
          cout<<endl;
     }
}