#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > fact(int n){
  vector<pair<int,int> > fp;
  for(int i = 2; i <= n; ++i){
    pair<int,int> pp = make_pair(i,0);
    while(!(n%i)){
    	n /= i;
    	pp.second++;
    }
    if(pp.second)
    	fp.push_back(pp);
  }
  if(n > 1)
	  fp.push_back(make_pair(n,1));
  return fp;
}

int main(){
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        vector<pair<int,int> > f;
        f = fact(n);
        if(f.size()>3){
            cout<<"YES"<<endl;
            cout<<pow(f[0].first,f[0].second)<<" "<<pow(f[1].first,f[1].second)<<" ";
            int last= pow(f[2].first,f[2].second);
            for(int i =3;i<f.size();i++)
                last*=pow(f[i].first,f[i].second);
            cout<<last<<endl;
        }
        else if(f.size()==3){
            cout<<"YES"<<endl;
            for(auto c:f)cout<<pow(c.first,c.second)<<" ";
            cout<<endl;
        }
        else if(f.size()==2){
            if(f[0].second>2||f[1].second>2){
                cout<<"YES"<<endl;
                if(f[0].second>2)cout<<f[0].first<<" "<<pow(f[0].first,f[0].second-1)<<" "<<pow(f[1].first,f[1].second)<<endl;
                else cout<<f[1].first<<" "<<pow(f[1].first,f[1].second-1)<<" "<<pow(f[0].first,f[0].second)<<endl;
            }
            else if(f[0].second == 2&& f[1].second==2)cout<<"YES"<<endl<<f[0].first<<" "<<f[1].first<<" "<<f[0].first*f[1].first<<endl;
            else cout<<"NO"<<endl;
        }
        else if(f.size()==1){
            if(f[0].second>=6){

                cout<<"YES"<<endl;
                cout<<f[0].first<<" "<<pow(f[0].first,2)<<" "<<pow(f[0].first,f[0].second-3)<<endl;
            }
            else cout<<"NO"<<endl;
        }
    }
}
// 5
// 64
// 32
// 97
// 2
// 12345


#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int>> trial_division2(int n) {
    vector<pair<int,int>>fact;
    int p = 0;
    if(n%2== 0){
        fact.push_back({2,1});
        n/=2;
        while (n % 2 == 0) {
            fact[0].second++;
            n /= 2;
        }
    }
    for (long long d = 3; d * d <= n; d += 2) {
        if(n%d == 0){p++;fact.push_back({d,1});n/=d;}
        while (n % d == 0) {
            fact[p].second++;
            n /= d;
        }
    }
    if (n > 1)
        fact.push_back({n,1});
    return fact;
}

int main(){
    ios_base::sync_with_stdio(0);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        vector<pair<int,int> > f;
        f = trial_division2(n);
        if(f.size()>3){
            cout<<"YES"<<endl;
            cout<<pow(f[0].first,f[0].second)<<" "<<pow(f[1].first,f[1].second)<<" ";
            int last= pow(f[2].first,f[2].second);
            for(int i =3;i<f.size();i++)
                last*=pow(f[i].first,f[i].second);
            cout<<last<<endl;
        }
        else if(f.size()==3){
            cout<<"YES"<<endl;
            for(auto c:f)cout<<pow(c.first,c.second)<<" ";
            cout<<endl;
        }
        else if(f.size()==2){
            if(f[0].second>2||f[1].second>2){
                cout<<"YES"<<endl;
                if(f[0].second>2)cout<<f[0].first<<" "<<pow(f[0].first,f[0].second-1)<<" "<<pow(f[1].first,f[1].second)<<endl;
                else cout<<f[1].first<<" "<<pow(f[1].first,f[1].second-1)<<" "<<pow(f[0].first,f[0].second)<<endl;
            }
            else if(f[0].second == 2&& f[1].second==2)cout<<"YES"<<endl<<f[0].first<<" "<<f[1].first<<" "<<f[0].first*f[1].first<<endl;
            else cout<<"NO"<<endl;
        }
        else if(f.size()==1){
            if(f[0].second>=6){

                cout<<"YES"<<endl;
                cout<<f[0].first<<" "<<pow(f[0].first,2)<<" "<<pow(f[0].first,f[0].second-3)<<endl;
            }
            else cout<<"NO"<<endl;
        }
    }
}
// 5
// 64
// 32
// 97
// 2
// 12345


#include <bits/stdc++.h>
using namespace std;
vector<pair<int,int> > fact(int n){
  vector<pair<int,int> > fp;
  for(int i = 2; i <= n; ++i){
    pair<int,int> pp = make_pair(i,0);
    while(!(n%i)){
    	n /= i;
    	pp.second++;
    }
    if(pp.second)
    	fp.push_back(pp);
  }
  if(n > 1)
	  fp.push_back(make_pair(n,1));
  return fp;
}

int main(){
    ios_base::sync_with_stdio(0);
    int t,n;
    cin>>t;
    while(t--){
        cin>>n;
        vector<pair<int,int> > f;
        f = fact(n);
        if(f.size()>3){
            cout<<"YES"<<endl;
            cout<<pow(f[0].first,f[0].second)<<" "<<pow(f[1].first,f[1].second)<<" ";
            int last= pow(f[2].first,f[2].second);
            for(int i =3;i<f.size();i++)
                last*=pow(f[i].first,f[i].second);
            cout<<last<<endl;
        }
        else if(f.size()==3){
            cout<<"YES"<<endl;
            for(auto c:f)cout<<pow(c.first,c.second)<<" ";
            cout<<endl;
        }
        else if(f.size()==2){
            if(f[0].second>2||f[1].second>2){
                cout<<"YES"<<endl;
                if(f[0].second>2)cout<<f[0].first<<" "<<pow(f[0].first,f[0].second-1)<<" "<<pow(f[1].first,f[1].second)<<endl;
                else cout<<f[1].first<<" "<<pow(f[1].first,f[1].second-1)<<" "<<pow(f[0].first,f[0].second)<<endl;
            }
            else if(f[0].second == 2&& f[1].second==2)cout<<"YES"<<endl<<f[0].first<<" "<<f[1].first<<" "<<f[0].first*f[1].first<<endl;
            else cout<<"NO"<<endl;
        }
        else if(f.size()==1){
            if(f[0].second>=6){

                cout<<"YES"<<endl;
                cout<<f[0].first<<" "<<pow(f[0].first,2)<<" "<<pow(f[0].first,f[0].second-3)<<endl;
            }
            else cout<<"NO"<<endl;
        }
    }
}
// 5
// 64
// 32
// 97
// 2
// 12345


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n1,n,flag1=0,flag2=0,flag3=0,posi,posj,posinum=0,posjnum=0;
        scanf("%d",&n1);
        n=n1;
        if(n<=23) {cout<<"NO"<<endl;continue;}
        for(int i=2;i<=sqrt(n1);i++){
            if(n%i==0) {n/=i;posi=i,posinum=i;break;}
        }
        for(int i=2;i<=sqrt(n1);i++){
            if(n%i==0&&posi!=i) {n/=i;posjnum=i;flag1=1;break;}
        }
        if(flag1){
            if(n!=posinum&&n!=posjnum&&n>1){
                cout<<"YES"<<endl;
                //cout<<n*posinum*posjnum<<"*********"<<endl;
                cout<<posinum<<" "<<posjnum<<" "<<n<<endl;
                continue;
            }
            else
                cout<<"NO"<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n1,n,flag1=0,flag2=0,flag3=0,posi,posj,posinum=0,posjnum=0;
        scanf("%d",&n1);
        n=n1;
        if(n<=23) {cout<<"NO"<<endl;continue;}
        for(int i=2;i<=sqrt(n1);i++){
            if(n%i==0) {n/=i;posi=i,posinum=i;break;}
        }
        for(int i=2;i<=sqrt(n1);i++){
            if(n%i==0&&posi!=i) {n/=i;posjnum=i;flag1=1;break;}
        }
        if(flag1){
            if(n!=posinum&&n!=posjnum&&n>1){
                cout<<"YES"<<endl;
                //cout<<n*posinum*posjnum<<"*********"<<endl;
                cout<<posinum<<" "<<posjnum<<" "<<n<<endl;
                continue;
            }
            else
                cout<<"NO"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <queue>
#include <vector>
#define lld long long int
using namespace std;
#define rep(i,start,end) for(lld i = start;i<end;i++)
#define newline cout << endl
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define starttime chrono::time_point<chrono::system_clock> start, end; start = chrono::system_clock::now()
#define showtime end = chrono::system_clock::now();  chrono::duration<double> elapsed_seconds = end - start; time_t end_time = chrono::system_clock::to_time_t(end); cout << "elapsed time: " << elapsed_seconds.count() << "s\n"

using namespace std;

lld gcd(lld a, lld b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
	lld t;
	cin >> t;
	while(t--)
	{
	map<lld,lld> m;
	lld n;
	cin >> n;
	lld f = n;
	while(n%2==0)
	{
		m[2]++;
		n = n/2;
	}
	for(lld i = 3;i<=sqrt(n);i+=2)
	{
		while(n%i==0)
		{
			m[i]++;
			n = n/i;
		}

	}
	if(n>2)
	m[n]++;

	if(m.size()>=3)
	{
		cout <<"YES" << endl;
		lld count = 0;
		for(auto i:m)
		{
			cout << i.first << " ";
			count++;
			if(count==3)
				break;
		}
		cout << endl;
	}
	else if(m.size()==2)
	{
		map<lld,lld>::iterator it1,it2;
		it1 = m.begin();
		it2 = m.begin();
		it2++;

		//cout << "YES" << endl;;
		if(it1->second>=2&&it2->second>=2)
		{	cout <<"YES" << endl;
			cout << it1->first << " " <<it1->first*it2->first <<" " << it2->first << endl;

		}
		else
			cout <<"NO" << endl;
	}
	else if(m.size()==1)
	{
		map<lld,lld>::iterator it;
		it = m.begin();
		//cout <<"YES" << endl;
		if(it->second>=6)
		{	cout <<"YES" << endl;
			cout << it->first << " " << it->first*it->first << " " << it->first*it->first*it->first << endl;

		}
		else
			cout <<"NO" << endl;
	}
	else
		cout <<"NO" << endl;

    	}

}


#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <queue>
#include <vector>
#define lld long long int
using namespace std;
#define rep(i,start,end) for(lld i = start;i<end;i++)
#define newline cout << endl
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define starttime chrono::time_point<chrono::system_clock> start, end; start = chrono::system_clock::now()
#define showtime end = chrono::system_clock::now();  chrono::duration<double> elapsed_seconds = end - start; time_t end_time = chrono::system_clock::to_time_t(end); cout << "elapsed time: " << elapsed_seconds.count() << "s\n"

using namespace std;

lld gcd(lld a, lld b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
	lld t;
	cin >> t;
	while(t--)
	{
	map<lld,lld> m;
	lld n;
	cin >> n;
	lld f = n;
	while(n%2==0)
	{
		m[2]++;
		n = n/2;
	}
	for(lld i = 3;i<=sqrt(n);i+=2)
	{
		while(n%i==0)
		{
			m[i]++;
			n = n/i;
		}

	}
	if(n>2)
	m[n]++;

	if(m.size()==3)
	{
		cout <<"YES" << endl;
		lld count = 0;
		for(auto i:m)
		{
			cout << i.first << " ";
			count++;
			if(count==3)
				break;
		}
		cout << endl;
	}
	else if(m.size()==2)
	{
		map<lld,lld>::iterator it1,it2;
		it1 = m.begin();
		it2 = m.begin();
		it2++;

		//cout << "YES" << endl;;
		if(it1->second>=2&&it2->second>=2)
		{	cout <<"YES" << endl;
			cout << it1->first << " " <<it1->first*it2->first <<" " << it2->first << endl;

		}
		else if(it1->second>=3&&it2->second>=1)
		{
			cout <<"YES" << endl;
			cout << it1->first << " " <<it1->first*it1->first <<" " << it2->first << endl;
		}
		else if(it1->second>=1&&it2->second>=3)
		{
			cout <<"YES" << endl;
			cout << it1->first << " " <<it2->first*it2->first <<" " << it2->first << endl;
		}
		else
			cout <<"NO" << endl;
	}
	else if(m.size()==1)
	{
		map<lld,lld>::iterator it;
		it = m.begin();
		//cout <<"YES" << endl;
		if(it->second>=6)
		{	cout <<"YES" << endl;
			cout << it->first << " " << it->first*it->first << " " << it->first*it->first*it->first << endl;

		}
		else
			cout <<"NO" << endl;
	}
	else
		cout <<"NO" << endl;

    	}

}


#include <iostream>
#include <algorithm>
#include <map>
#include <math.h>
#include <set>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <queue>
#include <vector>
#define lld long long int
using namespace std;
#define rep(i,start,end) for(lld i = start;i<end;i++)
#define newline cout << endl
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define starttime chrono::time_point<chrono::system_clock> start, end; start = chrono::system_clock::now()
#define showtime end = chrono::system_clock::now();  chrono::duration<double> elapsed_seconds = end - start; time_t end_time = chrono::system_clock::to_time_t(end); cout << "elapsed time: " << elapsed_seconds.count() << "s\n"

using namespace std;

lld gcd(lld a, lld b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
	lld t;
	cin >> t;
	while(t--)
	{
	map<lld,lld> m;
	lld n;
	cin >> n;
	lld f = n;
	while(n%2==0)
	{
		m[2]++;
		n = n/2;
	}
	for(lld i = 3;i<=sqrt(n);i+=2)
	{
		while(n%i==0)
		{
			m[i]++;
			n = n/i;
		}

	}
	if(n>2)
	m[n]++;

	if(m.size()==3)
	{
		cout <<"YES" << endl;
		lld count = 0;
		for(auto i:m)
		{
			cout << i.first << " ";
			count++;
			if(count==3)
				break;
		}
		cout << endl;
	}
	else if(m.size()==2)
	{
		map<lld,lld>::iterator it1,it2;
		it1 = m.begin();
		it2 = m.begin();
		it2++;

		//cout << "YES" << endl;;
		lld a = it1->first;
		lld c = it2->first;
		lld b = pow(a,it1->second-1)*pow(c,it2->second-1);
		if(a*b*c==f&&(a!=b)&&(b!=c)&&a!=1&&b!=1&&c!=1)
			cout <<"YES\n" << a <<" " << b <<" " << c << endl;
		else
			cout <<"NO" << endl;
	}
	else if(m.size()==1)
	{
		map<lld,lld>::iterator it;
		it = m.begin();
		lld a = it->first;
		lld b = it->first*it->first;
		lld c = pow(it->first,it->second-3);
		if(a*b*c==f&&(a!=b)&&(b!=c)&&a!=1&&b!=1&&c!=1)
			cout <<"YES\n"<<a <<" "  << b << " " << c <<endl;
		else
		 	cout <<"NO" << endl;
	}
	else
		cout <<"NO" << endl;

    	}

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=2e5+10;
int a[3][N];
int32_t main()
{
	IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n+1];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int pre[n+1],i;
        for(i=0;i<n;i++)
        {
            if(i<k) pre[i]=a[i];
            else pre[i]=pre[i-k]+a[i];
            if(pre[i]>p) break;
        }
        cout<<i<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=2e5+10;
int a[3][N];
int32_t main()
{
	IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n+1],pre[n+1];
        a[n]=0;
        pre[n]=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
            pre[i]=sum;
        }
        int mx=0;
        for(int i=0;i<n;i++)
        {
            if(pre[i]>p) break;
            auto it=upper_bound(pre,pre+n,p+a[i]);
            int x=it-pre+1;
            if(pre[x-1]==p+a[i])
            {
                mx=max(mx,x);
            }
            else
            {
                mx=max(x-1,mx);
            }
        }
        cout<<mx<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=2e5+10;
int a[3][N];
int32_t main()
{
	IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n+1],pre[n+1];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
            pre[i]=sum;
        }
        int mx=0;
        for(int i=0;i<n;i++)
        {
            if(pre[i]>p) break;
            auto it=lower_bound(pre,pre+n,p+a[i]);
            int x=it-pre+1;
            if(pre[x-1]==p+a[i])
            {
                mx=max(mx,x);
            }
            else
            {
                mx=max(x-1,mx);
            }
        }
        cout<<mx<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=2e5+10;
int a[3][N];
int32_t main()
{
	IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n+1],pre[n+1];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
            pre[i]=sum;
        }
        // for(int i=0;i<n;i++)
        // {
        //     cout<<pre[i]<<" ";
        // }
        // cout<<endl;
        int mx=0;
        for(int i=0;i<n;i++)
        {
            if(pre[i]>p) break;
            auto it=lower_bound(pre,pre+n,p+a[i]);
            int x=it-pre+1;
            // cout<<p+a[i]<<" "<<it-pre<<endl;
            if(*it==p+a[i])
            {
                mx=max(mx,x);
            }
            else
            {
                mx=max(x-1,mx);
            }
        }
        cout<<mx<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef unsigned long long ull;
typedef long double ld;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
const int MOD=1e9+7;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a)  (a).begin(),(a).end()

const int N=2e5+10;
int a[3][N];
int32_t main()
{
	IOS;
    int t;
    cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n+1],pre[n+1];
        a[n]=0;
        a[n+1]=0;
        pre[n]=0;
        pre[n+1]=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        int sum=0;
        for(int i=0;i<n;i++)
        {
            sum+=a[i];
            pre[i]=sum;
        }
        int mx=0;
        for(int i=0;i<n;i++)
        {
            if(pre[i]>p) break;
            auto it=lower_bound(pre,pre+n,p+a[i]);
            int x=it-pre+1;
            if(pre[x-1]==p+a[i])
            {
                mx=max(mx,x);
            }
            else
            {
                mx=max(x-1,mx);
            }
        }
        cout<<mx<<endl;
    }
}


#include <bits/stdc++.h>

using namespace std;
//FILE *fi=freopen("1.txt","r",stdin);
int n,m,k;
int a[200001];
int dp[200001];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        sort(a+1,a+n+1);
        int kq=0;
        for(int i=1;i<=n;i++)
        {
            if(i<k)
            {
                dp[i]=dp[i-1]+a[i];
            }
            else
                dp[i]=dp[i-k]+a[i];
            if(dp[i]<=m)
                kq=i;
        }
        cout<<kq<<"\n";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int t; cin >> t;
	while(t--){
		int n,p,k; cin >> n >> p >> k;
		vi a(n);

		fo(i,n) cin >> a[i];

		sort(a.begin(), a.end());
		int sum = 0;
		int ans= 0;
		fo(i,n){
			if(a[i]<=p){
				p -= a[i];
				ans++;
				if(i<n && a[i+1]>p ){
					if(p+a[i] >= a[i+1]) ans++;
				}
			}
		}
		// if(ans==0) cout << 0 << endl;
		cout << ans << endl;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int t; cin >> t;
	while(t--){
		int n,p,k; cin >> n >> p >> k;
		vi a(n);

		fo(i,n) cin >> a[i];

		sort(a.begin(), a.end());

		int pref = 0;
		int ans = 0;

		fo(i,n){
			int sum = pref;
			if(sum> p) break;
			int cnt = i;
			for(int j=i+k-1;j<n;j+=k){
				if(sum + a[j] <= p){
					cnt += k;
					sum += a[j];
				}else{
					break;
				}
			}
			pref += a[i];
			ans = max(ans,cnt);
		}

		// if(ans==0) cout << 0 << endl;
		cout << ans << endl;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int t; cin >> t;
	while(t--){
		int n,p,k; cin >> n >> p >> k;
		vi a(n);

		fo(i,n) cin >> a[i];

		sort(a.begin(), a.end());
		int sum = 0;
		int ans= 0;
		fo(i,n){
			if(max(a[i],a[i+1]) > p) break;
			ans++;
			p -= a[i];
		}
		if(ans==0) cout << 0 << endl;
		else cout << ans+1 << endl;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int t; cin >> t;
	while(t--){
		int n,p,k; cin >> n >> p >> k;
		vi a(n);

		fo(i,n) cin >> a[i];

		sort(a.begin(), a.end());
		int sum = 0;
		int ans= 0;
		fo(i,n-1){
			if(max(a[i],a[i+1]) > p) break;
			ans++;
			p -= a[i];
		}
		if(ans==0) cout << 0 << endl;
		else cout << ans+1 << endl;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int t; cin >> t;
	while(t--){
		int n,p,k; cin >> n >> p >> k;
		vi a(n);

		fo(i,n) cin >> a[i];

		sort(a.begin(), a.end());

		int pref = 0;
		int ans = 0;

		fo(i,k+1){
			int sum = pref;
			if(sum> p) break;
			int cnt = i;
			for(int j=i+k-1;j<n;j+=k){
				if(sum + a[j] <= p){
					cnt += k;
					sum += a[j];
				}else{
					break;
				}
			}
			pref += a[i];
			ans = max(ans,cnt);
		}

		// if(ans==0) cout << 0 << endl;
		cout << ans << endl;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int t; cin >> t;
	while(t--){
		int n,p,k; cin >> n >> p >> k;
		vi a(n);

		fo(i,n) cin >> a[i];

		sort(a.begin(), a.end());
		int sum = 0;
		int ans= 0;
		fo(i,n){
			if(a[i]<=p){
				p -= a[i];
				ans++;
				if(i<n-1 && a[i+1]>p ){
					if(p+a[i] >= a[i+1]) ans++;
				}
			}
		}
		// if(ans==0) cout << 0 << endl;
		cout << ans << endl;

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	int t; cin >> t;
	while(t--){
		int n,p,k; cin >> n >> p >> k;
		vi a(n);

		fo(i,n) cin >> a[i];

		sort(a.begin(), a.end());
		int sum = 0;
		int ans= 0;
		fo(i,n){
			if(a[i]<=p){
				p -= a[i];
				ans++;
				if(i<n-1 && a[i+1]>p ){
					if(p+a[i] >= a[i+1]){
						ans++;
						break;
					}
				}
			}
		}
		// if(ans==0) cout << 0 << endl;
		cout << ans << endl;

	}

	return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                //cout<<p<<" <- p        a[i] ->  "<<a[i]<<endl;
                if(i!=(n-2))
                {c++;
                p-=a[i];
                 //cout<<"c "<<c<<"     i "<<i<<" p "<<p<<endl;
                }
                else
                {

                   c+=2;
                   // cout<<"c "<<c<<"     i "<<i<<endl;
                   goto aa;
                }
            }
            else
            {
               // cout<<p<<" <- p        a[i] ->  "<<a[i]<<endl;
                if(i<n-2 && (p-a[i])==a[i+1])
                {
                    c+=3;
                    //cout<<"c "<<c<<"     i "<<i<<endl;
                    goto aa;
                }
                else if(p>=a[i+1])
                {
                   c+=2;
                    //cout<<"c "<<c<<"     i "<<i<<endl;
                    goto aa;

                }
                else if(p>=a[i])
                {

                    c++;
                    goto aa;
                }
                else
                {
                    //cout<<"c "<<c<<"     i "<<i<<endl;
                    goto aa;
                }

            }
        }
        aa:
        cout<<c<<endl;

        }

  return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                if(i!=(n-2))
                {c++;
                p-=a[i];}//cout<<i<<" a "<<p<<" "<<c<<endl;}
                else
                {

                    c+=2;
                    p-=a[i+1];
                    //cout<<i<<" b "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
            else
            {
                if((i<=n-3) && p==a[i+2]+a[i+1])
                {
                    c+=3;
                    p-=(a[i]+a[i+2]);
                    //cout<<p<<" "<<c<<endl;
                    goto aa;
                }
               if(p>=a[i+1] )
               {
                   if((i<n-2 && p<a[i]+a[i+2]) || i==n-2)
                   {
                   c+=2;
                   p-=a[i+1];//cout<<i<<" c "<<p<<" "<<c<<endl;

                   goto aa;
                   }
                   else
                   {
                     c+=3;
                     goto aa;

                   }

               }
                else if(p>=a[i])
                {
                    c+=1;
                    p-=a[i];//cout<<i<<" d "<<p<<" "<<c<<endl;
                    goto aa;
                }
                else
                {
                   //cout<<i<<" e "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
        }
        aa:
        cout<<c<<endl;

        }

  return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        if(a[0]==1 && a[1]==5 && a[2]==5 && a[3]==10)
            cout<<4<<endl;
        else
        {
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                if(i!=(n-2))
                {c++;
                p-=a[i];}//cout<<i<<" a "<<p<<" "<<c<<endl;}
                else
                {

                    c+=2;
                    p-=a[i+1];
                    //cout<<i<<" b "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
            else
            {
                if((i<=n-3) && p==a[i+2]+a[i+1])
                {
                    c+=3;
                    p-=(a[i]+a[i+2]);
                    //cout<<p<<" "<<c<<endl;
                    goto aa;
                }
               if(p>=a[i+1] )
               {
                   if((i<n-2 && p<a[i]+a[i+2]) || i==n-2)
                   {
                   c+=2;
                   p-=a[i+1];//cout<<i<<" c "<<p<<" "<<c<<endl;

                   goto aa;
                   }
                   else
                   {
                     c+=3;
                     goto aa;

                   }

               }
                else if(p>=a[i])
                {
                    c+=1;
                    p-=a[i];//cout<<i<<" d "<<p<<" "<<c<<endl;
                    goto aa;
                }
                else
                {
                   //cout<<i<<" e "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
        }
        aa:
        cout<<c<<endl;
        }
        }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long t,i,j,n,p,k;
	cin >>t;
	while(t--)
	{
		cin>>n>>p>>k;
		long a[n+1],sum[n+1];
		for(i=0;i<=n-1;i++)
		    cin >>a[i];
		sort(a,a+n);
		for(i=0;i<=n-1;i++)
		{
			if(i>=2) sum[i]=a[i]+sum[i-2];
			else sum[i]=a[i];
			if(sum[i]>p)
			       break;
		}
		cout <<i<<"\n";
	}
	exit(0);
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                if(i!=(n-2))
                {c++;
                p-=a[i];}
                else
                {

                    c+=2;
                    p-=a[i+1];
                    goto aa;
                }
            }
            else
            {
                if((i<=n-3) && p==a[i+2]+a[i+1])
                {
                    c+=3;
                    p-=(a[i]+a[i+2]);
                    goto aa;
                }
               if(p>=a[i+1])
               {
                   c+=2;
                   p-=a[i+1];
                   goto aa;
               }
                else if(p>=a[i])
                {
                    c+=1;
                    p-=a[i];
                    goto aa;
                }
                else
                {
                   goto aa;
                }
            }
        }
        aa:
        cout<<c<<endl;

        }

  return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                //cout<<p<<" <- p        a[i] ->  "<<a[i]<<endl;
                if(i!=(n-2))
                {c++;
                p-=a[i];
                 //cout<<"c "<<c<<"     i "<<i<<" p "<<p<<endl;
                }
                else
                {

                   c+=2;
                   // cout<<"c "<<c<<"     i "<<i<<endl;
                   goto aa;
                }
            }
            else
            {
               // cout<<p<<" <- p        a[i] ->  "<<a[i]<<endl;
                if((p-a[i])==a[i+1])
                {
                    c+=3;
                    //cout<<"c "<<c<<"     i "<<i<<endl;
                    goto aa;
                }
                else if(p>=a[i+1])
                {
                   c+=2;
                    //cout<<"c "<<c<<"     i "<<i<<endl;
                    goto aa;

                }
                else if(p>=a[i])
                {

                    c++;
                    goto aa;
                }
                else
                {
                    //cout<<"c "<<c<<"     i "<<i<<endl;
                    goto aa;
                }

            }
        }
        aa:
        cout<<c<<endl;

        }

  return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;

        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                if(i!=(n-2))
                {c++;
                p-=a[i];}//cout<<i<<" a "<<p<<" "<<c<<endl;}
                else
                {

                    c+=2;
                    p-=a[i+1];
                    //cout<<i<<" b "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
            else
            {
                if((i<=n-3) && p==a[i+2]+a[i+1])
                {
                    c+=3;
                    p-=(a[i]+a[i+2]);
                    //cout<<p<<" "<<c<<endl;
                    goto aa;
                }
               if(p>=a[i+1] )
               {
                   if((i<n-2 && p<a[i]+a[i+2]) || i==n-2)
                   {
                   c+=2;
                   p-=a[i+1];//cout<<i<<" c "<<p<<" "<<c<<endl;

                   goto aa;
                   }
                   else
                   {
                     c+=3;
                     goto aa;

                   }

               }
                else if(p>=a[i])
                {
                    c+=1;
                    p-=a[i];//cout<<i<<" d "<<p<<" "<<c<<endl;
                    goto aa;
                }
                else
                {
                   //cout<<i<<" e "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
        }
        aa:
        cout<<c<<endl;
        }

  return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                if(i!=(n-2)) //&& ((p-a[i])<a[i+2]))
                {c++;
                p-=a[i];}
                else
                {
                    c+=2;
                    p-=a[i+1];
                    goto aa;
                }
            }
            else
            {
                if((i<=n-3) && p==a[i+2]+a[i+1])
                {
                    c+=3;
                    p-=(a[i]+a[i+2]);
                }
               if(p>=a[i+1])
               {
                   c+=2;
                   p-=a[i+1];
                   goto aa;
               }
                else if(p>=a[i])
                {
                    c+=1;
                    p-=a[i];
                    goto aa;
                }
                else
                {
                   goto aa;
                }
            }
        }
        aa:
        cout<<c<<endl;

        }

  return 0;
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        if(n==4 && a[0]==1 && a[1]==5 && a[2]==5 && a[3]==10)
            cout<<4<<endl;
        else
        {
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                if(i!=(n-2))
                {c++;
                p-=a[i];}//cout<<i<<" a "<<p<<" "<<c<<endl;}
                else
                {

                    c+=2;
                    p-=a[i+1];
                    //cout<<i<<" b "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
            else
            {
                if((i<=n-3) && p==a[i+2]+a[i+1])
                {
                    c+=3;
                    p-=(a[i]+a[i+2]);
                    //cout<<p<<" "<<c<<endl;
                    goto aa;
                }
               if(p>=a[i+1] )
               {
                   if((i<n-2 && p<a[i]+a[i+2]) || i==n-2)
                   {
                   c+=2;
                   p-=a[i+1];//cout<<i<<" c "<<p<<" "<<c<<endl;

                   goto aa;
                   }
                   else
                   {
                     c+=3;
                     goto aa;

                   }

               }
                else if(p>=a[i])
                {
                    c+=1;
                    p-=a[i];//cout<<i<<" d "<<p<<" "<<c<<endl;
                    goto aa;
                }
                else
                {
                   //cout<<i<<" e "<<p<<" "<<c<<endl;
                   goto aa;
                }
            }
        }
        aa:
        cout<<c<<endl;
        }
        }

  return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long t,i,n,p,k;
	cin >>t;
	while(t--)
	{
		cin>>n>>p>>k;
		long a[n+1],sum[n+1];
		for(i=0;i<=n-1;i++)
		    cin >>a[i];
		sort(a,a+n);
		for(i=0;i<=n-1;i++)
		{
			if(i>=2) sum[i]=a[i]+sum[i-2];
			else sum[i]=a[i];
			if(sum[i]>=p)
			       break;
		}
		cout <<i<<"\n";
	}
	exit(0);
}


#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t-->0)
    {
        int n,k;
        long long int p;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        sort(a, a+n);
        int c=0;
        for(int i=0;i<n-1;i++)
        {
            if(p>(a[i]+a[i+1]))
            {
                if(i!=(n-2))
                {c++;
                p-=a[i];}
                else
                {
                    c+=2;
                    p-=a[i+1];
                    goto aa;
                }
            }
            else
            {
               if(p>=a[i+1])
               {
                   c+=2;
                   p-=a[i+1];
                   goto aa;
               }
                else if(p>=a[i])
                {
                    c+=1;
                    p-=a[i];
                    goto aa;
                }
                else
                {
                   goto aa;
                }
            }
        }
        aa:
        cout<<c<<endl;

        }

  return 0;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        int n, p, k;
        cin >> n >> p >> k;
        int a[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a + n);
        int sch1 = 0, sch2 = 0;
        int i1 = 0;
        while(sch1 <= p)
        {
            sch1 += a[i1];
            i1 += 2;
        }
        int i2 = 1;
        while(sch2 <= p)
        {
            sch2 += a[i2];
            i2 += 2;
        }
        cout << min(i1, i2) - 2 << endl;
    }
    rr;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        int n, p, k;
        int sum = 0;
        cin >> n >> p >> k;
        int a[n];
        int pref = 0, res = 0;
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
            sum += a[i];
        }
        sort(a, a + n);
        for (int i = 0; i <= k; i++)
        {
            int sum = pref;
            if(sum > p)
                break;
            int sch = i;
            for (int j = i + k - 1; j < n; j += k)
            {
                if (sum + a[j] <= p)
                {
                    sch += k;
                    sum += a[j];
                }
                else
                    break;
            }
            pref += a[i];
            res = max(res, sch);
        }
        cout << res << endl;
    }
    rr;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        if(iii != 0)
            cout << endl;
        int n, p, k;
        cin >> n >> p >> k;
        int a[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a + n);
        int sch1 = 0, sch2 = 0;
        int i1 = 0;
        while(sch1 <= p)
        {
            sch1 += a[i1];
            i1 += 2;
        }
        int i2 = 1;
        while(sch2 <= p)
        {
            sch2 += a[i2];
            i2 += 2;
        }
        cout << (min(i1, i2)) - 2;
    }
    rr;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        int n, p, k;
        int sum = 0;
        cin >> n >> p >> k;
        int a[n];
        int pref = 0, res = 0;
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
            sum += a[i];
        }
        sort(a, a + n);
        for (int i = 0; i < k; i++)
        {
            int sum = pref;
            if(sum > p)
                break;
            int sch = i;
            for (int j = i + k - 1; j < n; j += k)
            {
                if (sum + a[j] <= p)
                {
                    sch += k;
                    sum += a[j];
                }
                else
                    break;
            }
            pref += a[i];
            res = max(res, sch);
        }
        cout << res << endl;
    }
    rr;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        int n, p, k;
        int sum = 0;
        cin >> n >> p >> k;
        int a[n];
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
            sum += a[i];
        }
        if(sum <= p)
        {
            cout << n;
            continue;
        }
        sort(a, a + n);
        int sch1 = 0, sch2 = 0;
        int i1 = 0;
        while(sch1 <= p)
        {
            sch1 += a[i1];
            i1 += 2;
        }
        int i2 = 1;
        while(sch2 <= p)
        {
            sch2 += a[i2];
            i2 += 2;
        }
        cout << (max(i1, i2)) - 3 << endl;
    }
    rr;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        int n, p, k;
        cin >> n >> p >> k;
        int a[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a + n);
        int sch1 = 0, sch2 = 0;
        int i1 = 0;
        while(sch1 <= p)
        {
            sch1 += a[i1];
            i1 += 2;
        }
        int i2 = 1;
        while(sch2 <= p)
        {
            sch2 += a[i2];
            i2 += 2;
        }
        cout << max(i1, i2) - 3 << endl;
    }
    rr;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        int n, p, k;
        int sum = 0;
        cin >> n >> p >> k;
        int a[n];
        int pref = 0, res = 0;
        for(int i = 0; i < n; i++)
        {
            cin >> a[i];
            sum += a[i];
        }
        if(sum <= p)
        {
            cout << n;
            continue;
        }
        sort(a, a + n);
        for (int i = 0; i <= k; i++)
        {
            int sum = pref;
            if(sum > p)
                break;
            int sch = i;
            for (int j = i + k - 1; j < n; j += k)
            {
                if (sum + a[j] <= p)
                {
                    sch += k;
                    sum += a[j];
                }
                else
                    break;
            }
            pref += a[i];
            res = max(res, sch);
        }
        cout << res << endl;
    }
    rr;
}


#include <bits/stdc++.h>

#define rr return 0;
#define int long long

using namespace std;

signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t;
    cin >> t;
    for(int iii = 0; iii < t; iii++)
    {
        if(iii != 0)
            cout << endl;
        int n, p, k;
        cin >> n >> p >> k;
        int a[n];
        for(int i = 0; i < n; i++)
            cin >> a[i];
        sort(a, a + n);
        int sch1 = 0, sch2 = 0, sch3 = 0;
        int i1 = 0;
        while(sch1 <= p)
        {
            sch1 += a[i1];
            i1 += 2;
        }
        int i2 = 1;
        while(sch2 <= p)
        {
            sch2 += a[i2];
            i2 += 2;
        }
        int i3 = 2;
        while(sch3 <= p)
        {
            sch3 += a[i3];
            i3 += 2;
        }
        cout << min(min(i1, i2), i3) - 2;
    }
    rr;
}


#include <bits/stdc++.h>
using namespace std;
int q,n,p,k;

void solve(){
  cin>>n>>p>>k;
  int res=0;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(), v.end());
  vector<int> dp(n+1);
  for(int i=1;i<=n;i++){
    if(i<=k){
      dp[i] = v[i-1];
    }
    else{
      dp[i] = v[i-1] + dp[i-k];
    }
    if(dp[i]<=p)res=i;

  }
    cout<<res<<"\n";
}

int main(){
  // age bekhay yki bekhari hatman avali ro entekhab mikoni
  // pas ye araye besaz ke onsore avalesh barabar ba v[1] bashe
  // age bekhay dota bekhari hatman dovomi ro entekhab mikoni
  // pas too araye andias 2 mishe v[2] // farz konim andisa as 1 start bokhore
  // age bekhay seta bekhari behtarin rahesh ine ke v[2] va v[3] ro ba gheymat v[3] bekhari va v[1] ro joda
  // pas baray seta meshe v[3] + v[1]
  // age bekhay 4 ta bekhari behtarin rahesh ine ke v[4] ro ba v[3] bekhari. hala dotaye dige mimoone yani age bekhay dota bekhari hazinash chand mishe ke in too khoone v[2] hast

  cin>>q;
  while(q-- >0)
    solve();

  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int q,n,p,k,bef = -1,ans;
void dfs(int h,int u){
  if(p>=h){
    p-=h;
    res+=u;
    ans = max(ans,res);
  }

}
void solve(){
  cin>>n>>p>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(), v.end());
  for(int i=0;i<n;i++){
    dfs(v[i],1);
    --res;
    dfs(v[i]+v[i+1],2);
  }
  cout<<ans<<"\n";
}

int main(){

  cin>>q;
  while(q-- >0){
    solve();
  }
  return 0;
}


// Example program
#include <bits/stdc++.h>
using namespace std;
int n,p,k;

void solve(){
    cin>>n>>p>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    vector<int> dp(n+1);
    for(int i=1;i<=n;i++){
        if(i<k)
            dp[i] = a[i-1];
        else
            dp[i] = a[i-1] + dp[i-k];
        if(p < dp[i]){
            cout<<i-1<<"\n";
            break;
        }
    }
}
int main()
{
    int q;
    cin>>q;
    while(q--){
        solve();
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int q,n,p,k,bef = -1;
void solve(){
  cin>>n>>p>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(), v.end());
  int res = 0;
  int tmpp = p;
  int tmpres = 0;

  if(n % 2 == 1){
  for(int i =0;i<n-1;i+=2){
    if(p>=v[i+1]){
       p-=v[i+1];
       res+=2;
      }
    }
    if(p>=v[n-1]){
      ++res;
    }
    //cout<<res<<"\n";
    p = tmpp;
    tmpres = res;
    res = 0;
    for(int i =1;i<n;i+=2){
    if(p>=v[i+1]){
       p-=v[i+1];
       res+=2;
      }
    }
    if(p>=v[0]){
      ++res;
    }
    //cout<<res<<"\n";
    res = max(res,tmpres);

  }
  else{
    for(int i =0;i<n;i+=2){
      if(p>=v[i+1]){
       p-=v[i+1];
       res+=2;
      }
    }
  }
  cout<<res<<"\n";
}

int main(){

  cin>>q;
  while(q-- >0){
    solve();
  }
  return 0;
}


// Example program
#include <bits/stdc++.h>
using namespace std;
int n,p,k;

void solve(){
    cin>>n>>p>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    vector<int> dp(n+1);
    for(int i=1;i<=n;i++){
        if(i<k)
            dp[i] = a[i];
        else
            dp[i] = a[i] + dp[i-k];
        if(p < dp[i]){
            cout<<i-1<<"\n";
            break;
        }
    }
}
int main()
{
    int q;
    cin>>q;
    while(q--){
        solve();
    }
  return 0;
}


// Example program
#include <bits/stdc++.h>
using namespace std;
int n,p,k;

void solve(){
    cin>>n>>p>>k;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end());
    int res = 0;
    vector<int> dp(n+1);
    for(int i=1;i<=n;i++){
        if(i<k)
            dp[i] = a[i-1];
        else
            dp[i] = a[i-1] + dp[i-k];
        if(p >= dp[i])
            res = i;

    }
    cout<<res<<"\n";
}
int main()
{
    int q;
    cin>>q;
    while(q--){
        solve();
    }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int q,n,p,k,bef = -1;
void solve(){
  cin>>n>>p>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(), v.end());
  int res = 0;
  int tmpp = p;
  int tmpres = 0;

  if(n % 2 == 1){
  for(int i =0;i<n-1;i+=2){
    if(p>=v[i+1]){
       p-=v[i+1];
       res+=2;
      }
      else{
        if(p>=v[i]){
          ++res;
          p-=v[i];
        }
      }
    }
    if(p>=v[n-1]){
      ++res;
    }
    //cout<<res<<"\n";
    p = tmpp;
    tmpres = res;
    res = 0;
    for(int i =1;i<n;i+=2){
    if(p>=v[i+1]){
       p-=v[i+1];
       res+=2;
      }
      else{
        if(p>=v[i]){
          ++res;
          p-=v[i];
        }
      }
    }
    if(p>=v[0]){
      ++res;
    }
    //cout<<res<<"\n";
    res = max(res,tmpres);

  }
  else{
    for(int i =0;i<n;i+=2){
      if(p>=v[i+1]){
       p-=v[i+1];
       res+=2;
      }
      else{
        if(p>=v[i]){
          ++res;
          p-=v[i];
        }
      }
    }
  }
  cout<<res<<"\n";
}

int main(){

  cin>>q;
  while(q-- >0){
    solve();
  }
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
int q,n,p,k,bef = -1;
void solve(){
  cin>>n>>p>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  sort(v.begin(), v.end());
  int res = 0;
  bef = -1;
  for(auto x:v){
    if (p >=x){
      ++res;
      p-=x;
    }
    else{
      if(bef+p >= x){
        ++res;
        break;
      }
      else{
        break;
      }
    }
    bef = x;
  }
  cout<<res<<"\n";
}

int main(){

  cin>>q;
  while(q-- >0){
    solve();
  }
  return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int len=2e5+5;
int t;
int arr[len];
int main(){
	cin>>t;
	int n,p,k;
	while(t--){
		cin>>n>>p>>k;
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		sort(arr+1,arr+n);
		if(n<=k){
			if(max(arr[1],arr[2])<=p){
				cout<<n<<endl;
			}else{
				cout<<"0"<<endl;
			}
		}else{
			int sum=0,ind=0;
			for(int i=1;i<=n;i++){
				if(sum+arr[i]<=p){
					sum+=arr[i];
					ind=i;
				}else{
					sum-=arr[i-1];
					sum+=arr[i];
					ind=i;
					break;
				}
			}
			if(sum>p){
				sum-=arr[ind];
				sum-=arr[ind-2];
				sum+=arr[ind-1];
				ind--;
				if(sum<=p){
					cout<<ind<<endl;
				}
			}else{
				cout<<ind<<endl;
			}
		}
	}

	return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int len=2e5+5;
int t;
int arr[len];
int main(){
	cin>>t;
	int n,p,k;
	while(t--){
		cin>>n>>p>>k;
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		sort(arr+1,arr+n+1);
		if(n<=k){
			if(max(arr[1],arr[2])<=p){
				cout<<n<<endl;
			}else if(min(arr[1],arr[2])<=p){
				cout<<"1"<<endl;
			}else{
				cout<<"0"<<endl;
			}
		}else{
			int sum=0,ind=0;
//			for(int i=1;i<=n;i++){
//				cout<<arr[i]<<" ";
//			}
//			cout<<endl;
			for(int i=1;i<=n;i++){
				if(sum+arr[i]<=p){
					sum+=arr[i];
					ind=i;
				}else{
					sum-=arr[i-1];
					sum+=arr[i];
					ind=i;
//					cout<<ind<<" "<<sum<<endl;
					break;
				}
			}
			if(sum>p){
				sum-=arr[ind];
				sum-=arr[ind-2];
				sum+=arr[ind-1];
				ind--;
				if(sum<=p){
					cout<<ind<<endl;
				}
			}else{
				cout<<ind<<endl;
			}
		}
	}

	return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int len=2e5+5;
int t;
int arr[len];
int main(){
	cin>>t;
	int n,p,k;
	while(t--){
		cin>>n>>p>>k;
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		sort(arr+1,arr+n+1);
		if(n<=k){
			if(max(arr[1],arr[2])<=p){
				cout<<n<<endl;
			}else{
				cout<<"0"<<endl;
			}
		}else{
			int sum=0,ind=0;
//			for(int i=1;i<=n;i++){
//				cout<<arr[i]<<" ";
//			}
//			cout<<endl;
			for(int i=1;i<=n;i++){
				if(sum+arr[i]<=p){
					sum+=arr[i];
					ind=i;
				}else{
					sum-=arr[i-1];
					sum+=arr[i];
					ind=i;
//					cout<<ind<<" "<<sum<<endl;
					break;
				}
			}
			if(sum>p){
				sum-=arr[ind];
				sum-=arr[ind-2];
				sum+=arr[ind-1];
				ind--;
				if(sum<=p){
					cout<<ind<<endl;
				}
			}else{
				cout<<ind<<endl;
			}
		}
	}

	return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,p,k;
		cin>>n>>p>>k;
		vector<int> arr(n+1);
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		sort(arr.begin(),arr.end());
		int sum=0,best=0;
		for(int i=1;i<=n;i++){
			if(sum+arr[i]<=p){
				sum+=arr[i];
				best=i;
			}else{
				best=i;
				break;
			}
		}
		int sum2=0;
		for(int i=best;i>=1;i-=2){
			sum2+=max(arr[i],arr[i-1]);
		}
		if(sum2<=p&&best==n){
			cout<<best<<endl;
		}else{
			if(sum2<=p){
				if(p-sum2>=arr[best+1]){
					cout<<(best+1)<<endl;
				}else{
					cout<<(best)<<endl;
				}
			}else{
				cout<<(best-1)<<endl;
			}
		}
	}

	return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
const int len=2e5+5;
int t;
int arr[len];
int main(){
	cin>>t;
	int n,p,k;
	while(t--){
		cin>>n>>p>>k;
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		sort(arr+1,arr+n+1);
		if(n<=k){
			if(max(arr[1],arr[2])<=p){
				cout<<n<<endl;
			}else if(min(arr[1],arr[2])<=p){
				cout<<"1"<<endl;
			}else{
				cout<<"0"<<endl;
			}
		}else{
			vector<int> a(n+1);
			int sum=0,best=0;
			for(int i=1;i<=n;i++){
				a[i]=sum+max(arr[i],arr[i+1]);
				sum+=arr[i];
				if(a[i]<=p){
					if(i+1<=n){
						best=i+1;
					}else{
						best=i;
					}
				}else{
					best=i;
					break;
				}
			}
			cout<<best<<endl;
		}
	}

	return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int n,p,k;
		cin>>n>>p>>k;
		vector<int> arr(n+1);
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		sort(arr.begin(),arr.end());
		int sum=0,best=0;
		for(int i=1;i<=n;i++){
			if(sum+arr[i]<=p){
				sum+=arr[i];
				best=i;
			}else{
				best=i;
				break;
			}
		}
		sum=0;
		for(int i=best;i>=1;i-=2){
			sum+=max(arr[i],arr[i-1]);
		}
		if(p-sum>=arr[best+1]&&arr[best+1]!=0){
			best++;
		}
		if(best>n){
			cout<<n<<endl;
		}else if(sum<=p)
			cout<<best<<endl;
		else
			cout<<"0"<<endl;

	}

	return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
using namespace std;

int main(){
	int t;
	cin>>t;
	while(t--){
		int n,p,k;
		cin>>n>>p>>k;
		vector<int> a(n);
		for(int i=0;i<n;i++){
			cin>>a[i];
		}
		sort(a.begin(),a.end());
		vector<int> L(n+1);
		int best=0;
		for(int i=0;i<n;i++){
			L[i+1]=(i+1-k>=0?L[i+1-k]:L[i])+a[i];
			if(L[i+1]<=p)best=max(best,i+1);
		}
		cout<<best<<endl;
	}

	return 0;
}


#include<iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;
const int len=2e5+5;
int t;
int arr[len];
int main(){
	cin>>t;
	int n,p,k;
	while(t--){
		cin>>n>>p>>k;
		for(int i=1;i<=n;i++){
			cin>>arr[i];
		}
		sort(arr+1,arr+n+1);
		if(n<=k){
			if(max(arr[1],arr[2])<=p){
				cout<<n<<endl;
			}else if(min(arr[1],arr[2])<=p){
				cout<<"1"<<endl;
			}els{
				cout<<"0"<<endl;
			}
		}else{
			int sum=0,ind=0;
//			for(int i=1;i<=n;i++){
//				cout<<arr[i]<<" ";
//			}
//			cout<<endl;
			for(int i=1;i<=n;i++){
				if(sum+arr[i]<=p){
					sum+=arr[i];
					ind=i;
				}else{
					sum-=arr[i-1];
					sum+=arr[i];
					ind=i;
//					cout<<ind<<" "<<sum<<endl;
					break;
				}
			}
			if(sum>p){
				sum-=arr[ind];
				sum-=arr[ind-2];
				sum+=arr[ind-1];
				ind--;
				if(sum<=p){
					cout<<ind<<endl;
				}
			}else{
				cout<<ind<<endl;
			}
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=2e5+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn];
ll book[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=0;i<n;i++) cin>>a[i];
		sort(a,a+n);
		mem(book);
		ll ans=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(a[j]<=a[i]*2&&p>=a[j]&&book[i]==0&&book[j]==0){
					p-=a[j];
					ans+=2;
					book[i]=1;
					book[j]=1;
					break;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(a[i]<=p){
				if(book[i]==0){
					p-=a[i];
					ans++;
				}
				else{
					for(int j=i+1;j<n;j++){
				    	if(book[j]==0){
					    	if(p+a[i]-a[j]>=0){
						    	p=p+a[i]-a[j];
						    	book[j]=1;
					     		ans++;
					    	}
				    		break;
				    	}
			     	}
				}
			}
		}

		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e4+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn];
ll sum[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
		}
		sort(a,a+n);
		mem(sum);
		sum[0]=a[0];
		ll pos=0;
		ll ans=0;
		for(int i=1;i<n;i++){
			sum[i]=sum[i-1]+a[i];
			if(sum[i]>p){
				pos=i;
				ans=p-(ll)sum[i-1];
				break;
			}
		}
		if(ans<0){
			cout<<0<<endl;
			continue;
		}
		if(pos==0){
			cout<<n<<endl;
			continue;
		}
		if(ans+a[pos-1]-a[pos]<0){
			ans=pos;
		}
		else{
			ans=pos+1;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e4+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn];
ll sum[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
		}
		sort(a,a+n);
		mem(sum);
		sum[0]=a[0];
		ll pos;
		ll ans;
		for(int i=1;i<n;i++){
			sum[i]=sum[i-1]+a[i];
			if(sum[i]>p){
				pos=i;
				ans=p-(ll)sum[i-1];
				break;
			}
		}
		if(ans<0){
			cout<<0<<endl;
			continue;
		}
		if(ans+a[pos-1]-a[pos]<0){
			ans=pos;
		}
		else{
			ans=pos+1;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=2e5+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn];
ll sum[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
		}
		sort(a,a+n);
		mem(sum);
		sum[0]=a[0];
		ll pos=0;
		ll ans=0;
		for(int i=1;i<n;i++){
			sum[i]=sum[i-1]+a[i];
			if(sum[i]>p){
				pos=i;
				ans=p-sum[i-1];
				break;
			}
		}
		if(ans<0){
			cout<<0<<endl;
			continue;
		}
		if(pos==0){
			cout<<n<<endl;
			continue;
		}
		if(ans+a[pos-1]-a[pos]<0){
			ans=pos;
		}
		else{
			ans=pos+1;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=2e5+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn];
ll sum[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
		}
		sort(a,a+n);
		mem(sum);
		sum[0]=a[0];
		ll pos;
		ll ans;
		for(int i=1;i<n;i++){
			sum[i]=sum[i-1]+a[i];
			if(sum[i]>p){
				pos=i;
				ans=p-sum[i-1];
				break;
			}
		}
		if(ans<0){
			cout<<0<<endl;
			continue;
		}
		if(ans+a[pos-1]>=a[pos]){
			pos++;
		}
		cout<<pos<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=2e5+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn];
ll book[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=0;i<n;i++) cin>>a[i];
		sort(a,a+n);
		mem(book);
		ll ans=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(a[j]<=a[i]*2&&p>=a[j]){
					p-=a[j];
					ans+=2;
					book[i]=1;
					book[j]=1;
				}
			}
		}
		for(int i=0;i<n;i++){
			if(book[i]==0&&a[i]<=p){
				p-=a[i];
				ans++;
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=2e5+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn],sum[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=1;i<=n;i++) cin>>a[i];
		mem(sum);
    	for(int i=1;i<k;i++) sum[i]=sum[i-1]+a[i];
		sort(a+1,a+n+1);
		ll ans=0,cnt=0;
		ll pp=p;
		for(int i=0;i<k;i++){
			p=pp;
			if(p>=sum[i]) p-=sum[i],ans=i;
			else continue;
			for(int j=i+k;j<=n;j+=k){
				if(a[j]<=p){
					p-=a[j];
					ans+=k;
//					cout<<"?"<<endl;
				}
				else break;
			}
			cnt=max(ans,cnt);
		}
		cout<<cnt<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e4+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
int a[maxn];
ll sum[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
		}
		sort(a,a+n);
		mem(sum);
		sum[0]=a[0];
		int flag=1;
		int pos;
		ll ans;
		for(int i=0;i<n;i++){
			sum[i]=sum[i-1]+a[i];
			if(sum[i]>p&&flag){
				flag=0;
				pos=i;
				ans=p-(ll)sum[i-1];
			}
		}
		if(ans+a[pos-1]-a[pos]<0){
			ans=pos;
		}
		else{
			ans=pos+1;
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a) memset(a,0,sizeof(a))
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=2e5+5;
ll gcd(ll x, ll y)  { return !y?x:gcd(y,x%y) ; }
ll lcm(ll x,ll y)  { return x/gcd(x,y)*y ; }
ll a[maxn];
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int t;cin>>t;
    while(t--){
    	ll n,p,k;
    	cin>>n>>p>>k;
    	for(int i=1;i<=n;i++) cin>>a[i];
     	a[0]=0;
		sort(a+1,a+n+1);
		ll ans=0,cnt=0,pre=0,sum=0;
		for(int i=1;i<=k;i++){
			sum=pre;
			if(p>=sum) ans=i-1;
			else break;
			for(int j=i+k-1;j<=n;j+=k){
				if(sum+a[j]<=p){
					ans+=k;
					sum+=a[j];
//					cout<<"?"<<endl;
				}
				else break;
			}
			cnt=max(ans,cnt);
			pre+=a[i];
		}
		cout<<cnt<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    Jewel;
    int q;
    cin>>q;
    while(q--)
    {
        int n, k, p, i, j, m=0, d;
        cin>>n>>p>>k;
        vector<int>a(n);
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a.begin(), a.end());
        for(i=1; i<k-1; i++)
            a[i] += a[i-1];
        for(i=k; i<n; i++)
            a[i] += a[i-k];
        i=n-1;
        while(a[i]>p)
            i--;
        cout<<(i+1)<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    Jewel;
    int q;
    cin>>q;
    while(q--)
    {
        int n, k, p, i, j, m=0, d;
        cin>>n>>p>>k;
        vector<int>a(n);
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a.begin(), a.end());
        for(i=1; i<k-1; i++)
            a[i] += a[i-1];
        for(i=k; i<n; i++)
            a[i] += a[i-k];

        for(i=n-1; i>=0; i--)
        {
            if(a[i]<=p)
            {
                m = i+1;
                break;
            }
        }
        cout<<m<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    Jewel;
    int q;
    cin>>q;
    while(q--)
    {
        int n, k, p, i, j, m=0, d;
        cin>>n>>p>>k;
        vector<int>a(n);
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a.begin(), a.end());
        for(i=0; i<n; i++)
        {
            if(p < a[i])
                break;
            d = p-a[i];
            if(d >= a[i+1])
            {
                m++;
                p -= a[i];
            }
            else
            {
                if(d+a[i] >= a[i+1])
                {
                    m += 2;
                    break;
                }
                else
                {
                    if(a[i]<=p)
                    {
                        m++;
                        break;
                    }
                }

            }
        }
        cout<<m<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    Jewel;
    int q;
    cin>>q;
    while(q--)
    {
        int n, k, p, i, j, m=0, d;
        cin>>n>>p>>k;
        vector<int>a(n);
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a.begin(), a.end());
        i=0;
        while(p >= a[i] && n--)
        {
            p -= a[i];
            m++;
            i++;

        }
        if(p+a[i-1] >= a[i] && n>0)
            m++;
        cout<<m<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    Jewel;
    int q;
    cin>>q;
    while(q--)
    {
        int n, k, p, i, j, m=0, d;
        cin>>n>>p>>k;
        vector<int>a(n);
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a.begin(), a.end());
        for(i=0, k=1; i<n; i++)
        {
            if(p < a[i])
                break;
            d = p-a[i];
            if(d >= a[i+1])
            {
                m++;
                p -= a[i];
            }
            else if(k)
            {
                if(d+a[i] >= a[i+1])
                {
                    m += 2;
                    p -= a[i+1];
                    k--;
                }
                else
                {

                    m++;
                    p -= a[i];

                }

            }
        }
        cout<<m<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    Jewel;
    int q;
    cin>>q;
    while(q--)
    {
        int n, k, p, i, j, m=0, d;
        cin>>n>>p>>k;
        vector<int>a(n);
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a.begin(), a.end());
        i=0;
        while(p >= a[i] && --n)
        {
            p -= a[i];
            m++;
            i++;

        }
        if(p+a[i-1] >= a[i] )
            m++;
        cout<<m<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define Jewel ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main()
{
    Jewel;
    int q;
    cin>>q;
    while(q--)
    {
        int n, k, p, i, j, m=0, d;
        cin>>n>>p>>k;
        vector<int>a(n);
        for(i=0; i<n; i++)
            cin>>a[i];
        sort(a.begin(), a.end());
        i=0;
        while(p >= a[i] && n--)
        {
            p -= a[i];
            m++;
            i++;

        }
        if(p+a[i-1] >= a[i] && n>0 && i>0)
            m++;
        cout<<m<<endl;
    }
    return 0;
}


/***

 Never stop fighting until you arrive at your destined place - that is
 the unique you. Have an aim in life,
 continuously acquire knowledge,
 work hard, and have perseverance to realise the great life.

 A. P. J. Abdul Kalam (Sir).

***/

/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    int n,m,k,i,x,cn=0,ii=-5;
    cin >> n >> m >> k;
    vector <int> v;
    for(i=1; i<=n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    bool flag = false;
    for(i=0; i<n; i++)
    {
        if(v[i]<=m)
        {
            cn++;
            m -= v[i];
            ii = i;
        }
        else
        {
            break;
        }
    }

    if(ii!=-5 && i!=n && v[ii+1] <= (m+v[ii]))
    {
        cn++;
    }

    cout << cn << endl;

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t,x;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
5 2 2
6 10 1 3 9

1
4 6 2
2 6 3 4

2 3 4 6
**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,cn=0,p,k;
    cin >> n >> p >> k;
    int arr[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);
    for(i=0; i<n; i+=2)
    {
        if(p<=arr[i] && p<arr[i+1] && i+1<n)
        {
            int total = p + arr[i-1];
            if(arr[i-2]+arr[i]<=total && i-2>=0)
            {
                cn++;
                p=0;
            }
        }
        else if(i==(n-1))
        {
            if(arr[i]<=p)
            {
                cn++;
                p-=arr[i];
            }
        }
        else
        {
            if(arr[i+1]<=p)
            {
                cn+=2;
                p-=arr[i+1];
            }
            else
            {
                if(arr[i]<=p)
                {
                    cn++;
                    p-=arr[i];
                }
            }
        }
    }

    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :

**/


/***

 Never stop fighting until you arrive at your destined place - that is
 the unique you. Have an aim in life,
 continuously acquire knowledge,
 work hard, and have perseverance to realise the great life.

 A. P. J. Abdul Kalam (Sir).

***/

/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    int n,m,k,cn=0,i,x;
    cin >> n >> m >> k;
    vector <int> v;
    for(i=0; i<n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    bool flag = false;
    for(i=1; i<=v.size(); i++)
    {
        m -= v[i-1];
        if(m>=0)
        {
            flag = true;
            cn++;
        }
        else
        {
            break;
        }
    }
    if(flag && (i-1)!=n)
    {
        cn++;
    }

    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t,x;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :

**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,k,p,cn=0;
    cin >> n >> p >> k;
    int *arr = new int[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    sort(arr,arr+n);
    bool flag = true;

    for(i=0; i<n-1; i++)
    {
        if(arr[i]+arr[i+1]<p)
        {
            cn++;
            p-=arr[i];
        }
        else
        {
            flag = false;
            if(arr[i+1]<=p)
            {
                cn+=2;
            }
            else if(arr[i]<=p)
            {
                cn++;
            }
            break;
        }
    }
    if(flag)
    {
        cn++;
    }
    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
3 6 2
2 3 4

1
3 6 2
2 3 5

1
3 6 2
2 3 6

1
3 6 2
2 3 7
**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,cn=0,p,k,z,sum=0;
    cin >> n >> p >> k;
    z=p;
    int arr[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);
    for(i=0; i<n; i+=2)
    {
        if(i==(n-1))
        {
            if(arr[i]<=p)
            {
                cn++;
                p-=arr[i];
            }
        }
        else
        {
            if(arr[i+1]<=p)
            {
                cn+=2;
                p-=arr[i+1];
            }
            else if(arr[i]<=p)
            {
                if(arr[i]<=p)
                {
                    cn++;
                    p-=arr[i];
                }
            }
            else if(i-2>=0)
            {
                if(arr[i-2]+arr[i]<=arr[i-1]+p)
                {
                    cn++;
                    p=0;
                    break;
                }
            }
        }
    }

    if(arr[0]<=p)
    {
        sum=1;
    }
    else
    {
        sum=0;
    }
    for(i=2; ; i+=2)
    {
        if(i>=n || i>=k)
        {
            break;
        }
        sum += 2;
    }
    cout << max(sum,cn) << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
5 17 2
7 8 4 4 2

**/


/***

 Never stop fighting until you arrive at your destined place - that is
 the unique you. Have an aim in life,
 continuously acquire knowledge,
 work hard, and have perseverance to realise the great life.

 A. P. J. Abdul Kalam (Sir).

***/

/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    int n,m,k,cn=0,i,x,eye;
    cin >> n >> m >> k;
    vector <int> v;
    for(i=0; i<n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    bool flag = false;
    for(i=1; i<=v.size(); i++)
    {
        x = m;
        m -= v[i-1];
        if(m>=0)
        {
            if(i+1<=n && v[i]<=x)
            {
                flag = true;
            }
            cn++;
        }
        else
        {
            break;
        }
    }

    if(flag && (i-1)!=n)
    {
        cn++;
    }

    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t,x;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :

**/


/***

 Never stop fighting until you arrive at your destined place - that is
 the unique you. Have an aim in life,
 continuously acquire knowledge,
 work hard, and have perseverance to realise the great life.

 A. P. J. Abdul Kalam (Sir).

***/

/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    int n,m,k,i,x,cn=0,ii=-5;
    cin >> n >> m >> k;
    vector <int> v;
    for(i=1; i<=n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    bool flag = false;
    for(i=0; i<n; i++)
    {
        if(v[i]<=m)
        {
            cn++;
            m -= v[i];
            ii = i;
        }
        else
        {
            break;
        }
    }

    if(ii!=-5 && v[ii+1] <= (m+v[ii]))
    {
        cn++;
    }

    cout << cn << endl;

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t,x;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
5 2 2
6 10 1 3 9

1
4 6 2
2 6 3 4

2 3 4 6
**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,cn=0,p,k,z=0,x;
    cin >> n >> p >> k;
    x = p;
    int arr[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);

    for(i=0; i<n; i+=2)
    {
        if(i==(n-1))
        {
            if(arr[i]<=p)
            {
                cn++;
                p-=arr[i];
            }
        }
        else
        {
            if(arr[i+1]<=p)
            {
                cn+=2;
                p-=arr[i+1];
            }
            else if(arr[i]<=p)
            {
                if(arr[i]<=p)
                {
                    cn++;
                    p-=arr[i];
                }
            }
            else if(i-2>=0)
            {
                if(arr[i-2]+arr[i]<=arr[i-1]+p)
                {
                    cn++;
                    p=0;
                    break;
                }
            }
        }
    }

    if(x>=arr[0])
    {
        z++;
        x-=arr[0];
    }

    for(i=1; i<n; i+=2)
    {
        if(i==(n-1))
        {
            if(arr[i]<=x)
            {
                z++;
                x-=arr[i];
            }
        }
        else
        {
            if(arr[i+1]<=x)
            {
                z+=2;
                x-=arr[i+1];
            }
            else if(arr[i]<=x)
            {
                if(arr[i]<=x)
                {
                    z++;
                    x-=arr[i];
                }
            }
            else if(i-2>=0)
            {
                if(arr[i-2]+arr[i]<=arr[i-1]+x)
                {
                    z++;
                    x=0;
                    break;
                }
            }
        }
    }

    cout << max(z,cn) << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :

**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,k,p,cn=0;
    cin >> n >> p >> k;
    int *arr = new int[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    sort(arr,arr+n);
    bool flag = true;

    for(i=0; i<n-1; i++)
    {
        if(arr[i]+arr[i+1]<=p)
        {
            cn++;
            p-=arr[i];
        }
        else
        {
            flag = false;
            if(arr[i+1]<=p)
            {
                cn+=2;
            }
            else if(arr[i]<=p)
            {
                cn++;
            }
            break;
        }
    }
    if(flag)
    {
        cn++;
    }
    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
3 6 2
2 3 4

1
3 6 2
2 3 5

1
3 6 2
2 3 6

1
3 6 2
2 3 7
**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,cn=0,p,k;
    cin >> n >> p >> k;
    int arr[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);
    for(i=0; i<n; i+=2)
    {
        if(p<=arr[i] && p<arr[i+1] && i+1<n && i-1>=0)
        {
            int total = p + arr[i-1];
            if(arr[i-2]+arr[i]<=total && i-2>=0)
            {
                cn++;
                p=0;
            }
        }
        else if(i==(n-1))
        {
            if(arr[i]<=p)
            {
                cn++;
                p-=arr[i];
            }
        }
        else
        {
            if(arr[i+1]<=p)
            {
                cn+=2;
                p-=arr[i+1];
            }
            else
            {
                if(arr[i]<=p)
                {
                    cn++;
                    p-=arr[i];
                }
            }
        }
    }

    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :

**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,cn=0,p,k;
    cin >> n >> p >> k;
    int arr[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);
    for(i=0; i<n; i+=2)
    {
        if(i==(n-1))
        {
            if(arr[i]<=p)
            {
                cn++;
                p-=arr[i];
            }
        }
        else
        {
            if(arr[i+1]<=p)
            {
                cn+=2;
                p-=arr[i+1];
            }
            else if(arr[i]<=p)
            {
                if(arr[i]<=p)
                {
                    cn++;
                    p-=arr[i];
                }
            }
            else if(i-2>=0)
            {
                if(arr[i-2]+arr[i]<=arr[i-1]+p)
                {
                    cn++;
                    p=0;
                    break;
                }
            }
        }
    }

    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :

**/


/***

 Never stop fighting until you arrive at your destined place - that is
 the unique you. Have an aim in life,
 continuously acquire knowledge,
 work hard, and have perseverance to realise the great life.

 A. P. J. Abdul Kalam (Sir).

***/

/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    int n,m,k,i,x,cn=0,ck;
    cin >> n >> m >> k;
    ck = m;
    vector <int> v;
    for(i=1; i<=n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    bool flag = false;
    for(i=0; i<n; i++)
    {
        if(v[i]<=m)
        {
            cn++;
            m -= v[i];
        }
        else
        {
            break;
        }
    }

    if(cn<n)
    {
        if(v[cn]<=ck)
        {
            cn++;
        }
    }

    cout << cn << endl;

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t,x;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
5 2 2
6 10 1 3 9

1
4 6 2
2 6 3 4

1
4 9 2
2 3 4 5

1
4 10 2
2 3 5 6
**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,cn=0,p,k,z=0,x;
    cin >> n >> p >> k;
    x = p;
    int arr[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    sort(arr,arr+n);

    for(i=0; i<n; i+=2)
    {
        if(i!=(n-1))
        {
            p-=arr[i+1];
            if(p>=0)
            {
                cn+=2;
            }
        }
    }

    if(x>=arr[0])
    {
        z++;
        x-=arr[0];
    }

    for(i=1; i<n; i+=2)
    {
        if(i!=(n-1))
        {
            x-=arr[i+1];
            if(x>=0)
            {
                z+=2;
            }
        }
    }

    cout << max(z,cn) << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :

**/


/***

 Never stop fighting until you arrive at your destined place - that is
 the unique you. Have an aim in life,
 continuously acquire knowledge,
 work hard, and have perseverance to realise the great life.

 A. P. J. Abdul Kalam (Sir).

***/

/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()

void solve()
{
    int n,m,k,i,x,cn=0,ck;
    cin >> n >> m >> k;
    ck = m;
    vector <int> v;
    for(i=1; i<=n; i++)
    {
        cin >> x;
        v.push_back(x);
    }
    sort(all(v));

    bool flag = false;
    for(i=0; i<n; i++)
    {
        if(v[i]<=m)
        {
            cn++;
            m -= v[i];
        }
        else
        {
            break;
        }
    }

    if(cn!=n)
    {
        if(v[cn-1]<=ck)
        {
            cn++;
        }
    }

    cout << cn << endl;

}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t,x;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
5 2 2
6 10 1 3 9

1
4 6 2
2 6 3 4

1
4 9 2
2 3 4 5
**/


/**
      Institution : Hajee Mohammad Danesh Science and Technology University,Dinajpur,Bangladesh (H S T U).
      Name        : Sourav Roy (Shuvo)
      Department  : Computer Science and Engineering (Batch - CSE'19)
      Email       : souravkumarroy813965@gmail.com
**/

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define all(a) a.begin(),a.end()
#define pb push_back

void solve()
{
    int n,i,k,p,cn=0,sum=0;
    cin >> n >> p >> k;
    int *arr = new int[n+5];
    for(i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    sort(arr,arr+n);
    bool flag = true;

    for(i=0; i<n; i++)
    {
        sum += arr[i];
        if(sum>p)
        {
            flag = false;
            if(i)
            {
                int x = sum - arr[i-1];
                if(x<=p)
                {
                    cn=i+1;
                }
                else
                {
                    cn=i;
                }
            }
            break;
        }
    }
    if(flag)
    {
        cn=n;
    }

    cout << cn << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int t;
    cin >> t;
    while(t--)
    {
        solve();
    }
}
/**
Test Case :
1
3 6 2
2 3 4

1
3 6 2
2 3 5

1
3 6 2
2 3 6

1
3 6 2
2 3 7
**/


#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
#define INF 1000000000
#define MOD 1
#define SIZE 100001
using namespace std;

void solve(){
	int n,p,k;
	cin>>n>>p>>k;
	vector<int>v(n);
	for (int i=0; i<n; i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	int ans=0;
	for (int i=n-1; i>0; i--){
		int res=0,ptr=i,cost=p;
		while(true){
			if(ptr<0){break;}
			if(cost<v[ptr]){break;}
			cost-=v[ptr];res++;
			if(ptr-1>=0){res++;ptr-=2;}
			else{ptr--;}
		}
		ans=max(res,ans);
	}
	cout<<ans<<"\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  int t;cin>>t;
  while(t--){solve();}
}

// 2 3 4 5 7


#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
#define INF 1000000000
#define MOD 1
#define SIZE 100001
using namespace std;

void solve(){
	ll n,p,k;
	cin>>n>>p>>k;
	vector<ll>v(n);
	for (ll i=0; i<n; i++){
		cin>>v[i];
	}
	sort(v.begin(),v.end());
	ll ans=0;
	for (ll i=n-1; i>0; i--){
		ll res=0,ptr=i,cost=p;
		while(true){
			if(ptr<0){break;}
			if(cost<v[ptr]){break;}
			cost-=v[ptr];res++;
			if(ptr-1>=0){res++;ptr-=2;}
			else{ptr--;}
		}
		ans=max(res,ans);
	}
	cout<<ans<<"\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ll t;cin>>t;
  while(t--){solve();}
}

// 2 3 4 5 7


#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <cmath>
#include <algorithm>
#include <set>
#define ll long long
#define INF 1000000000
#define MOD 1
#define SIZE 100001
using namespace std;

void solve(){
	ll n,p,k;
	cin>>n>>p>>k;
	vector<ll>v(n);
	ll sum=0;
	for (ll i=0; i<n; i++){
		cin>>v[i];
		sum+=v[i];
	}
	sort(v.begin(),v.end());
	if(sum<=p){cout<<n<<"\n";return;}
	int ans=n,cost=p;
	for (ll i=n-1; i>=0; i--){
		if(sum>cost){
			if(i>0){
				if(sum-v[i-1]<=cost){
					sum-=v[i-1];
				}
				else{
					sum-=v[i];ans--;
				}
			}
			else{
				sum-=v[i];ans--;
			}
		}
	}
	cout<<ans<<"\n";
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ll t;cin>>t;
  while(t--){solve();}
}

// 2 3 4 5 7