#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;cin>>t;
    while(t--)
    {
        vector<int>v1;
        long long int i,n,p,k;cin>>n>>p>>k;
        for(i=0;i<n;i++)
        {
            long long int temp;cin>>temp;
            v1.push_back(temp);
        }
        sort(v1.begin(),v1.end());
        i = 0;
        int count = 0 , pc = 0 ;
        while(pc<p && count<=n)
        {
              if(i>=n)
              {
                  break;
              }
              if(i+1>=n)
              {
                  if(pc+v1[i]<=p)
                  {
                      count++;
                  }
                  break;
              }
              if(i+2>=n)
              {

                  if(pc+v1[i+1]<=p)
                  {
                      count+=2;
                  }
                  else if(pc+v1[i]<=p)
                  {
                      count++;
                  }
                  break;
              }
              if(v1[i]==v1[i+1] && pc+v1[i]<=p)
              {
                  i++;
                  count++;
              }

              if(pc+v1[i]+v1[i+2]<=p)
              {
                count += 3;
                pc += v1[i]+v1[i+2];
                i = 3+i;
              }
              else if(pc+v1[i+1]<=p)
              {
                  count += 2;
                  pc += v1[i+1];
                  i++;
              }
              else if(pc + v1[i]<=p)
              {
                  count++;
                  pc += v1[i];
                  i++;
              }

        }
        cout<<count<<endl;
    }
}
// pc += v1[i+1];


#include<stdio.h>
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
void solve( vector<int> arr, int p, int k) {

}
int main() {
    int t;
    cin >> t;
    for(int x = 0; x< t; x++) {
        int n, p, k;
        cin >> n >> p >> k;
        vector<int> arr(n);
        for(int i=0; i< n; i++) {
          cin>>arr[i];
        }
       if (arr.size() == 1) {
        if (arr[0] <= p) {
            cout << 1<< endl;
           continue;
        }
        cout << 0<< endl;
        continue;
    }
    sort(arr.begin(), arr.end());
    long dp[100001][2];
    dp[0][0] = arr[0];
    dp[0][1] = 10000000000000000;
    dp[1][0] = arr[0] + arr[1];
    dp[1][1] = arr[1];
    int ans  = 0;
    if (arr[0] <= p) ans = 1;
    if (min(dp[1][0], dp[1][1]) <= p) ans = 2;
    for (int i = 2; i< n ; i++) {
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + arr[i];
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + arr[i];
        if (min(dp[i][0], dp[i][1]) <= p) ans = i + 1;
else break;
    }
    cout << ans << endl;
    }
}


#include<stdio.h>
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
void solve( vector<int> arr, int p, int k) {

}
int main() {
    int t;
    cin >> t;
    for(int x = 0; x< t; x++) {
        int n, p, k;
        cin >> n >> p >> k;
        vector<int> arr(n);
        for(int i=0; i< n; i++) {
          cin>>arr[i];
        }
       if (arr.size() == 1) {
        if (arr[0] <= p) {
            cout << 1<< endl;
           continue;
        }
        cout << 0<< endl;
        continue;
    }
    sort(arr.begin(), arr.end());
    long dp[2][2];
    dp[0][0] = arr[0];
    dp[0][1] = 10000000000000000;
    dp[1][0] = arr[0] + arr[1];
    dp[1][1] = arr[1];
    int ans  = 0;
    if (arr[0] <= p) ans = 1;
    if (min(dp[1][0], dp[1][1]) <= p) ans = 2;
    for (int i = 2; i< n ; i++) {
        int a = min(dp[1][0], dp[1][1]) + arr[i];
        int b = min(dp[0][0], dp[0][1]) + arr[i];
        if (min(a, b) <= p) ans = i + 1;
        dp[0][0] = dp[1][0];
        dp[0][1] = dp[1][1];
        dp[1][0] = a;
        dp[1][1] = b;
    }
    cout << ans << endl;
    }
}


#include<stdio.h>
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
void solve( vector<int> arr, int p, int k) {
    if (arr.size() == 1) {
        if (arr[0] <= p) {
            cout << 1<< endl;
            return;
        }
        cout << 0<< endl;
        return;
    }
    sort(arr.begin(), arr.end());
    long dp[100001][2];
    dp[0][0] = arr[0];
    dp[0][1] = 1000000000000000000;
    dp[1][0] = arr[0] + arr[1];
    dp[1][1] = arr[1];
    int ans  = 0;
    if (arr[0] <= p) ans = 1;
    if (min(dp[1][0], dp[1][1]) <= p) ans = 2;
    for (int i = 2; i< arr.size() ; i++) {
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + arr[i];
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + arr[i];
        if (min(dp[i][0], dp[i][1]) <= p) ans = i + 1;
    }
    cout << ans << endl;
}
int main() {
    int t;
    cin >> t;
    for(int x = 0; x< t; x++) {
        int n, p, k;
        cin >> n >> p >> k;
        vector<int> arr;
        for(int i=0; i< n; i++) {
            int x;
            cin >> x;
            arr.push_back(x);
        }
        solve(arr, p, k);
    }
}


#include<stdio.h>
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
void solve( vector<int> arr, int p, int k) {
    if (arr.size() == 1) {
        if (arr[0] <= p) {
            cout << 1<< endl;
            return;
        }
        cout << 0<< endl;
        return;
    }
    sort(arr.begin(), arr.end());
    long dp[100001][2];
    dp[0][0] = arr[0];
    dp[0][1] = 10000000000000000;
    dp[1][0] = arr[0] + arr[1];
    dp[1][1] = arr[1];
    int ans  = 0;
    if (arr[0] <= p) ans = 1;
    if (min(dp[1][0], dp[1][1]) <= p) ans = 2;
    int n = arr.size();
    for (int i = 2; i< n ; i++) {
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + arr[i];
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + arr[i];
        if (min(dp[i][0], dp[i][1]) <= p) ans = i + 1;
    }
    cout << ans << endl;
}
int main() {
    int t;
    cin >> t;
    for(int x = 0; x< t; x++) {
        int n, p, k;
        cin >> n >> p >> k;
        vector<int> arr;
        for(int i=0; i< n; i++) {
            int x;
            cin >> x;
            arr.push_back(x);
        }
        solve(arr, p, k);
    }
}


#include<stdio.h>
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
void solve( vector<int> arr, int p, int k) {
    if (arr.size() == 1) {
        if (arr[0] <= p) {
            cout << 1<< endl;
            return;
        }
        cout << 0<< endl;
        return;
    }
    sort(arr.begin(), arr.end());
    long dp[100001][2];
    dp[0][0] = arr[0];
    dp[0][1] = 100000000000000000;
    dp[1][0] = arr[0] + arr[1];
    dp[1][1] = arr[1];
    int ans  = 0;
    if (arr[0] <= p) ans = 1;
    if (min(dp[1][0], dp[1][1]) <= p) ans = 2;
    for (int i = 2; i< arr.size() ; i++) {
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + arr[i];
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + arr[i];
        if (min(dp[i][0], dp[i][1]) <= p) ans = i + 1;
    }
    cout << ans << endl;
}
int main() {
    int t;
    cin >> t;
    for(int x = 0; x< t; x++) {
        int n, p, k;
        cin >> n >> p >> k;
        vector<int> arr;
        for(int i=0; i< n; i++) {
            int x;
            cin >> x;
            arr.push_back(x);
        }
        solve(arr, p, k);
    }
}


#include<stdio.h>
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
void solve( vector<int> arr, int p, int k) {
    if (arr.size() == 1) {
        if (arr[0] <= p) {
            cout << 1<< endl;
            return;
        }
        cout << 0<< endl;
        return;
    }
    sort(arr.begin(), arr.end());
    long dp[100001][2];
    dp[0][0] = arr[0];
    dp[0][1] = 1000000000000000000;
    dp[1][0] = arr[0] + arr[1];
    dp[1][1] = arr[1];
    int ans  = 0;
    if (arr[0] <= p) ans = 1;
    if (min(dp[1][0], dp[1][1]) <= p) ans = 2;
    int n = arr.size();
    for (int i = 2; i< n ; i++) {
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + arr[i];
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + arr[i];
        if (min(dp[i][0], dp[i][1]) <= p) ans = i + 1;
    }
    cout << ans << endl;
}
int main() {
    int t;
    cin >> t;
    for(int x = 0; x< t; x++) {
        int n, p, k;
        cin >> n >> p >> k;
        vector<int> arr;
        for(int i=0; i< n; i++) {
            int x;
            cin >> x;
            arr.push_back(x);
        }
        solve(arr, p, k);
    }
}


#include<stdio.h>
#include<iostream>
#include <vector>
#include <algorithm>

using namespace std;
void solve( vector<int> arr, int p, int k) {

}
int main() {
    int t;
    cin >> t;
    for(int x = 0; x< t; x++) {
        int n, p, k;
        cin >> n >> p >> k;
        vector<int> arr(n);
        for(int i=0; i< n; i++) {
          cin>>arr[i];
        }
       if (arr.size() == 1) {
        if (arr[0] <= p) {
            cout << 1<< endl;
           continue;
        }
        cout << 0<< endl;
        continue;
    }
    sort(arr.begin(), arr.end());
    long dp[100001][2];
    dp[0][0] = arr[0];
    dp[0][1] = 10000000000000000;
    dp[1][0] = arr[0] + arr[1];
    dp[1][1] = arr[1];
    int ans  = 0;
    if (arr[0] <= p) ans = 1;
    if (min(dp[1][0], dp[1][1]) <= p) ans = 2;
    for (int i = 2; i< n ; i++) {
        dp[i][0] = min(dp[i-1][0], dp[i-1][1]) + arr[i];
        dp[i][1] = min(dp[i-2][0], dp[i-2][1]) + arr[i];
        if (min(dp[i][0], dp[i][1]) <= p) ans = i + 1;
    }
    cout << ans << endl;
    }
}


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

int main() {
	// your code goes here
	long long int t,n,p,k,A[100000],i,c;
	cin>>t;
	while(t--)
	{
	    c=0;
	    cin>>n>>p>>k;
	    i=0;
	    while(i<n)
	    {
	        cin>>A[i];
	        i++;
	    }
	    sort(A,A+n);
	    if(n>1)
	    {

	     if(A[0]<=p)
	     c=1;
	     //P[1]=A[1];
	     if(A[1]<=p)
	     c=2;
	    }
	    else if(n>0)
	    {
	        //[0]=A[0];
	        if(A[0]<=p)
	        c=1;
	    }
	    i=2;
	    while(i<n)
	    {
	        A[i]=A[i-2]+A[i];
	        if(A[i]<=p)
	        {
	         c++;
	        }
	        else
	        break;
	        i++;
	    }
	    cout<<c<<endl;
	}
	return 0;
}


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

int main() {
	// your code goes here
	long long int t,n,p,k,A[100000],i,P[100000],c;
	cin>>t;
	while(t--)
	{
	    c=0;
	    cin>>n>>p>>k;
	    i=0;
	    while(i<n)
	    {
	        cin>>A[i];
	        i++;
	    }
	    sort(A,A+n);
	    if(n>1)
	    {
	    P[0]=A[0];
	    P[1]=A[1];
	    }
	    else if(n>0)
	    {
	        P[0]=A[0];
	    }
	    i=2;
	    while(i<n)
	    {
	        P[i]=P[i-2]+A[i];
	        if(P[i]<=p)
	        {
	         c++;
	        }
	        else
	        break;
	        i++;
	    }
	    if(c>0)
	    c+=2;
	    else
	    {
	        if(n>1 && P[1]<=p)
	        c=2;
	        else if(n>0 && P[0]<=p)
	        c=1;
	    }
	    cout<<c<<endl;
	}
	return 0;
}


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

    int main() {
    	// your code goes here
    	int t,n,p,k,A[100000],i,P[100000],c,f,h,m,s,min;
    	cin>>t;
    	while(t--)
    	{
    	    s=0;
    	    min=INT_MAX;
    	    c=0;
    	    cin>>n>>p>>k;
    	    i=0;
    	    while(i<n)
    	    {
    	        cin>>A[i];
    	        s+=A[i];
    	        if(A[i]<min)
    	        min=A[i];
    	        i++;
    	    }
    	    if(s<=p)
    	    cout<<n<<endl;
    	    else if(min>p)
    	    cout<<0<<endl;
    	    else
    	    {
    	    sort(A,A+n);
    	    if(n>0)
    	    {
    	        P[0]=A[0];
    	        if(P[0]<=p)
    	        c=1;
    	    }
    	    if(n>1)
    	    {
    	        P[1]=A[1];
    	        if(P[1]<=p)
    	        c=2;
    	    }
    	    if(c==2)
    	    {
    	    i=2;
    	    while(i<n)
    	    {
    	        P[i]=P[i-2]+A[i];
    	        if(P[i]<=p)
    	        c=i+1;
    	        else
    	        break;
    	        i++;
    	    }
    	    }
    	    cout<<c<<endl;
    	    }
    	}
    	return 0;
    }


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

    int main() {
    	// your code goes here
    	long long int t,n,p,k,A[100000],i,P[100000],c,f,h,m;
    	cin>>t;
    	while(t--)
    	{
    	    c=0;
    	    cin>>n>>p>>k;
    	    i=0;
    	    while(i<n)
    	    {
    	        cin>>A[i];
    	        i++;
    	    }
    	    sort(A,A+n);
    	    if(n>0)
    	    {
    	        P[0]=A[0];
    	        if(P[0]<=p)
    	        c=1;
    	    }
    	    if(n>1)
    	    {
    	        P[1]=A[1];
    	        if(P[1]<=p)
    	        c=2;
    	    }
    	    if(c==2)
    	    {
    	    i=2;
    	    while(i<n)
    	    {
    	        P[i]=P[i-2]+A[i];
    	        i++;
    	    }
    	    f=0;
    	    h=n-1;
    	    while(f<=h)
    	    {
    	        m=f+(h-f)/2;
    	        if(P[m]>p)
    	        h=m-1;
    	        else
    	        {
    	            c=m+1;
    	            f=m+1;
    	        }
    	    }
    	    }
    	    cout<<c<<endl;
    	}
    	return 0;
    }


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

    int main() {
    	// your code goes here
    	int t,n,p,k,A[100000],i,P[100000],c,f,h,m;
    	cin>>t;
    	while(t--)
    	{
    	    c=0;
    	    cin>>n>>p>>k;
    	    i=0;
    	    while(i<n)
    	    {
    	        cin>>A[i];
    	        i++;
    	    }
    	    sort(A,A+n);
    	    if(n>0)
    	    {
    	        P[0]=A[0];
    	        if(P[0]<=p)
    	        c=1;
    	    }
    	    if(n>1)
    	    {
    	        P[1]=A[1];
    	        if(P[1]<=p)
    	        c=2;
    	    }
    	    if(c==2)
    	    {
    	    i=2;
    	    while(i<n)
    	    {
    	        P[i]=P[i-2]+A[i];
    	        if(P[i]<=p)
    	        c=i+1;
    	        else
    	        break;
    	        i++;
    	    }
    	    }
    	    cout<<c<<endl;
    	}
    	return 0;
    }


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        long long int n,p,k;
        cin>>n>>p>>k;
        long long int a[n];
        for(long long int i=0;i<n;++i)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        long long int i=0,s=0,qq=-1;
        while(i<n-2 && n!=2)
        {
            long long int j=i,t=0,m=i,rrr=0;
            while(j<n-2 && p-t-s>0 && rrr==0)
            {
                if(a[j]+a[j+2]<=p-t-s)
                {
                    m+=3;
                    t+=(a[j]+a[j+2]);
                    j+=3;
                    //cout<<i<<" "<<t<<endl;
                }
                else
                {
                    if(a[j]+a[j+1]<=p-t-s)
                    {
                        m+=2;
                        t+=(a[j+1]);
                    }
                    else if(a[j]<=p-t-s)
                    {
                        ++m;
                        t+=a[j];
                    }

                    ++rrr;
                }
                qq=max(m,qq);
                //cout<<i<<" "<<qq<<endl;
            }
            s+=a[i];
            ++i;

        }
        if(n==2)
        {
            if(a[1]<=p)
            {
                qq=2;
            }
            else if(a[1]>p && a[0]<=p)
            {
                qq=1;
            }
            else
            {
                qq=0;
            }
        }
        cout<<qq<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void s()
{
    long long int n,p,m;
    cin>>n>>p>>m;
    long long int a[n];
    for(long long int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    long long int prefix[n];
    prefix[0]=a[0],prefix[1]=a[1];
    for(long long int j=2;j<n;++j)
    {
        prefix[j]=a[j]+prefix[j-2];
    }
    long long int r=0;
    for(long long int i=0;i<n;++i)
    {
        if(prefix[i]<=p)
            r=i+1;
    }
    cout<<r<<endl;
}
int main()
{
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        s();
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        long long int n,p,k;
        cin>>n>>p>>k;
        long long int a[n];
        for(long long int i=0;i<n;++i)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        long long int qqq=-1,s=0;
        for(long long int i=0;i<n-2;++i)
        {
            long long int j=i,m=i,ttt=0;
            long long int curr=p-s;
            while(j<n-2 && curr>0 && ttt==0)
            {
                if(curr>=(a[j]+a[j+2]))
                {
                    m+=3;
                    curr-=(a[j]+a[j+2]);
                    j+=3;
                }
                else if(curr>=(a[j+1]))
                {
                    m+=2;
                    curr-=(a[j+1]);
                    ++ttt;
                    ++j;
                }
                else if(curr>=a[j])
                {
                    ++m;
                    curr-=a[j];
                    ++ttt;
                    ++j;
                }
                else
                {
                    ++ttt;
                }

            }
            qqq=max(qqq,m);
            s+=a[i];
        }

        if(n==2)
        {
            if(a[1]<=p)
            {
                qqq=2;
            }
            else if(a[1]>p && a[0]<=p)
            {
                qqq=1;
            }
            else
            {
                qqq=0;
            }
        }
        cout<<qqq<<endl;

    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        long long int n,p,k;
        cin>>n>>p>>k;
        long long int a[n];
        for(long long int i=0;i<n;++i)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        long long int qqq=-1,s=0;
        for(long long int i=0;i<n-2;++i)
        {
            long long int j=i,m=0;
            long long int curr=p-s;
            while(j<n-2 && curr)
            {
                if(curr>=(a[j]+a[j+2]))
                {
                    m+=3;
                    curr-=(a[j]+a[j+2]);
                }
                else if(curr>=(a[j+1]))
                {
                    ++m;
                    curr-=(a[j+1]);
                }
                else if(curr>=a[j])
                {
                    ++m;
                    curr-=a[j];
                }
                qqq=max(qqq,m);
                ++j;
            }
            s+=a[i];
        }

        if(n==2)
        {
            if(a[1]<=p)
            {
                qqq=2;
            }
            else if(a[1]>p && a[0]<=p)
            {
                qqq=1;
            }
            else
            {
                qqq=0;
            }
        }
        cout<<qqq<<endl;

    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        long long int n,p,k;
        cin>>n>>p>>k;
        long long int a[n];
        for(long long int i=0;i<n;++i)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        long long int qqq=-1,s=0;
        for(long long int i=0;i<n;++i)
        {
            long long int j=i,ttt=0,m=0;
            long long int curr=p-s;
            if(curr>=0)
            {
                m=i;
            }
            while(j<n && curr>0 && ttt==0)
            {
                if(j<n-2 && curr>=(a[j]+a[j+2]))
                {
                    m+=3;
                    curr-=(a[j]+a[j+2]);
                    j+=3;
                }
                else if(j<n-1 && curr>=(a[j+1]))
                {
                    m+=2;
                    curr-=(a[j+1]);
                    ++ttt;
                    ++j;
                }
                else if(curr>=a[j])
                {
                    ++m;
                    curr-=a[j];
                    ++ttt;
                    ++j;
                }
                else
                {
                    ++ttt;
                }

            }
            qqq=max(qqq,m);
            s+=a[i];
        }

        if(n==2)
        {
            if(a[1]<=p)
            {
                qqq=2;
            }
            else if(a[1]>p && a[0]<=p)
            {
                qqq=1;
            }
            else
            {
                qqq=0;
            }
        }
        cout<<qqq<<endl;

    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
void s()
{
    long long int n,p,m;
    cin>>n>>p>>m;
    long long int a[n];
    for(long long int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    long long int prefix[n];
    prefix[0]=a[0],prefix[1]=a[1];
    for(long long int j=2;j<n;++j)
    {
        prefix[j]=a[j]+prefix[j-2];
    }
    long long int r=0;
    for(long long int i=0;i<n;++i)
    {
        if(prefix[i]<=p)
            r=i+1;
    }
    cout<<r<<endl;
}
int main()
{
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        s();
    }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        long long int n,p,k;
        cin>>n>>p>>k;
        long long int a[n];
        for(long long int i=0;i<n;++i)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        long long int qqq=-1,s=0;
        for(long long int i=0;i<n;++i)
        {
            long long int j=i,ttt=0,m=0;
            long long int curr=p-s;
            if(curr>=0)
            {
                m=i;
            }
            while(j<n && curr>0 && ttt==0)
            {
                if(j<n-2 && curr>=(a[j]+a[j+2]))
                {
                    m+=3;
                    curr-=(a[j]+a[j+2]);
                    j+=3;
                }
                else if(j<n-1 && curr>=(a[j+1]))
                {
                    m+=2;
                    curr-=(a[j+1]);
                    ++ttt;
                    ++j;
                }
                else if(curr>=a[j])
                {
                    ++m;
                    curr-=a[j];
                    ++ttt;
                    ++j;
                }
                else
                {
                    ++ttt;
                }

            }
            qqq=max(qqq,m);
            if(i%2==1)
            {
                s+=(a[i]-a[i-1]);
            }
            else
            {
                s+=a[i];
            }

        }

        if(n==2)
        {
            if(a[1]<=p)
            {
                qqq=2;
            }
            else if(a[1]>p && a[0]<=p)
            {
                qqq=1;
            }
            else
            {
                qqq=0;
            }
        }
        cout<<qqq<<endl;

    }

    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int t;
    cin>>t;
    for(long long int it=0;it<t;++it)
    {
        long long int n,p,k;
        cin>>n>>p>>k;
        long long int a[n];
        for(long long int i=0;i<n;++i)
        {
            cin>>a[i];
        }
        sort(a,a+n);
        long long int qqq=-1,s=0;
        for(long long int i=0;i<n;++i)
        {
            long long int j=i,ttt=0,m=0;
            long long int curr=p-s;
            if(curr>=0)
            {
                m=i;
            }
            while(j<n && curr>0 && ttt==0)
            {
                if(j<n-2 && curr>=(a[j]+a[j+2]))
                {
                    m+=3;
                    curr-=(a[j]+a[j+2]);
                    j+=3;
                }
                else if(j<n-1 && curr>=(a[j+1]))
                {
                    m+=2;
                    curr-=(a[j+1]);
                    ++ttt;
                    ++j;
                }
                else if(curr>=a[j])
                {
                    ++m;
                    curr-=a[j];
                    ++ttt;
                    ++j;
                }
                else
                {
                    ++ttt;
                }

            }
            qqq=max(qqq,m);
            if(i!=1 && i%2==1)
            {
                s+=(a[i]-a[i-1]+a[i-2]);
            }
            else if(i!=0 && i%2==0)
            {
                s+=(a[i]-a[i-1]+a[i-2]);
            }
            else if(i==0)
            {
                s+=a[i];
            }
            else if(i==1)
            {
                s+=(a[i]-a[i-1]);
            }

        }

        if(n==2)
        {
            if(a[1]<=p)
            {
                qqq=2;
            }
            else if(a[1]>p && a[0]<=p)
            {
                qqq=1;
            }
            else
            {
                qqq=0;
            }
        }
        cout<<qqq<<endl;

    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

ll lcm(ll a, ll b)
{
    return (a * b) / __gcd(a, b);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll t;
    cin >> t;
    while (t--)
    {
        ll n, p, k;
        cin >> n >> p >> k;
        vector<ll> x(n);
        for (int i = 0; i < n; i++)
        {
            cin >> x[i];
        }

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

        if(n==2)
        {
            if(x[1]<=p)
            {
                cout<<"2"<<endl;
            }
            else if(x[0]<=p)
            {
                cout<<"1"<<endl;
            }
            else
            {
                cout<<"0"<<endl;
            }
            continue;
        }
        ll ans=0;
        for(int i=0;i<n-3+1;i++)
        {
            if(x[i]+x[i+2]<=p && i+1==n-3+1)
            {
                ans+=3;
                break;
            }
            else if(x[i]+x[i+2]<=p)
            {
                ans++;
                p-=x[i];
            }
            else
            {
                if(x[i+1]<=p)
                {
                    ans+=2;
                    break;
                }
                else if(x[i]<=p)
                {
                    ans++;
                    break;
                }
                else
                {
                    break;
                }
            }
        }

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


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

ll lcm(ll a, ll b)
{
    return (a * b) / __gcd(a, b);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll t;
    cin >> t;
    while (t--)
    {
        ll n, p, k;
        cin >> n >> p >> k;
        vector<ll> x(n);
        for (int i = 0; i < n; i++)
        {
            cin >> x[i];
        }

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

        ll ans=0;
        ll pre=0;
        for(int i=0;i<k;i++)
        {
            ll sum=pre;
            ll cnt=i;
            pre+=x[i];
            if(sum>p)
            {
                break;
            }
            for(int j = i+k-1;j<n;j+=k)
            {
                if(sum+x[j]<=p)
                {
                    sum+=x[j];
                    cnt+=k;
                }
                else
                {
                    break;
                }
            }

            ans = max(ans, cnt);
        }

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


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mk make_pair

void PLAY()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

/*ll v[1000000];
ll len[1000000];
ll cnt = 0;
vector<vector<ll>> x;
ll dfs(ll n)
{
    //cout<<n<<" a"<<endl;
    vis[n] = 1;
    for (int i = 0; i < x[n].size(); i++)
    {
        ll lol = x[n][i];
        if (!vis[lol])
        {
            dfs(lol);
            cnt++;
        }
    }
    return cnt;
}
void seth(ll a, ll b)
{
    if (vis[a] == 2)
        return;
    vis[a] = 2;
    len[a] = b;
    for (int i = 0; i < x[a].size(); i++)
    {
        ll lol = x[a][i];
        if (vis[lol] != 2)
        {
            seth(lol, b);
        }
    }
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll t;
    cin >> t;
    while (t--)
    {
        ll n, p, k;
        cin >> n >> p >> k;
        vector<ll> x(n);
        for (int i = 0; i < n; i++)
        {
            cin >> x[i];
        }

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

        ll cnt = 0;
        ll sum = 0;
        ll ans = 0;
        ll pre = 0;
        for(int i=0;i<=k;i++)
        {
            cnt = i;
            sum = pre;
            if(sum>p)
            {
                break;
            }
            for(int j = i+k-1;j<n;j+=k)
            {
                if(sum+x[j]<=p)
                {
                    sum+=x[j];
                    cnt+=k;
                }
                else
                {
                    break;
                }
            }

            pre += x[i];
            ans = max(ans, cnt);
        }

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


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

ll lcm(ll a, ll b)
{
    ll gcd = __gcd(a, b);

    a = a / gcd;
    if (a > 1e18 / b)
        return 1e18;

    return a * b;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n;
    cin>>n;
    vector<ll>x;
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            x.push_back(i);
        }
    }

    ll m = x.size();
    ll mini = LONG_LONG_MAX;
    ll a=0;
    ll b=0;
    for(int i=0;i<m;i++)
    {
        if(max(x[i], n/x[i])<mini && lcm(x[i], n/x[i])==n)
        {
            mini = max(x[i], n/x[i]);
            a = x[i];
            b = n/x[i];
        }
    }

    cout<<a<<" "<<b<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define mk make_pair

void PLAY()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

/*ll v[1000000];
ll len[1000000];
ll cnt = 0;
vector<vector<ll>> x;
ll dfs(ll n)
{
    //cout<<n<<" a"<<endl;
    vis[n] = 1;
    for (int i = 0; i < x[n].size(); i++)
    {
        ll lol = x[n][i];
        if (!vis[lol])
        {
            dfs(lol);
            cnt++;
        }
    }
    return cnt;
}
void seth(ll a, ll b)
{
    if (vis[a] == 2)
        return;
    vis[a] = 2;
    len[a] = b;
    for (int i = 0; i < x[a].size(); i++)
    {
        ll lol = x[a][i];
        if (vis[lol] != 2)
        {
            seth(lol, b);
        }
    }
}*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll t;
    cin >> t;
    while (t--)
    {
        ll n, p, k;
        cin >> n >> p >> k;
        vector<ll> x(n);
        for (int i = 0; i < n; i++)
        {
            cin >> x[i];
        }

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

        // ll cnt = 0;
        // ll sum = 0;
        // ll ans = 0;
        // ll j = k-1;
        if(n>=4)
        {
            if(p>=(x[3]+x[1]))
            {
                cout<<"4"<<endl;
            }
            else if(p>=(x[3]+x[0]) || p>=(x[2]+x[0]))
            {
                cout<<"3"<<endl;
            }
            else if(p>=(x[1]))
            {
                cout<<"2"<<endl;
            }
            else if(p>=x[0])
            {
                cout<<"1"<<endl;
            }
            else
            {
                cout<<"0"<<endl;
            }
        }
        else if(n==3)
        {
            if(p>=(x[2]+x[0]))
            {
                cout<<"3"<<endl;
            }
            else if(p>=(x[1]))
            {
                cout<<"2"<<endl;
            }
            else if(p>=x[0])
            {
                cout<<"1"<<endl;
            }
            else
            {
                cout<<"0"<<endl;
            }
        }
        else
        {
            if(p>=(x[1]))
            {
                cout<<"2"<<endl;
            }
            else if(p>=x[0])
            {
                cout<<"1"<<endl;
            }
            else
            {
                cout<<"0"<<endl;
            }
        }

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


#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

ll lcm(ll a, ll b)
{
    return (a * b) / __gcd(a, b);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll t;
    cin >> t;
    while (t--)
    {
        ll n, p, k;
        cin >> n >> p >> k;
        vector<ll> x(n);
        for (int i = 0; i < n; i++)
        {
            cin >> x[i];
        }

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

        ll ans=0;
        ll pre=0;
        for(int i=0;i<n;i++)
        {
            ll sum=pre;
            ll cnt=i;
            pre+=x[i];
            if(sum>p)
            {
                break;
            }
            for(int j = i+k-1;j<n;j+=k)
            {
                if(sum+x[j]<=p)
                {
                    sum+=x[j];
                    cnt+=k;
                }
                else
                {
                    break;
                }
            }

            ans = max(ans, cnt);
        }

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


#include<bits/stdc++.h>
using namespace std;
long long int val(long long int a[],int n,int p,int k,long long int dp[])
{

    dp[1]=a[1]; dp[0]=a[0];
    for(int i=2;i<=n;i++)
    {
       dp[i]=min(dp[i-2]+a[i],dp[i-1]+a[i]);
    }int res=-1;
    for(int i=0;i<=n;i++)
    {
        if(p>=dp[i])
        {
            res=max(res,i);
        }
    }
   return res+1;

}
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int n,p,k;
    cin>>n>>p>>k;
   long long  int a[n];
    for(int i=0;i<n;i++)
 cin>>a[i];long long int dp[n+1];memset(dp,-1,sizeof(dp));sort(a,a+n);
cout<< val(a,n,p,k,dp)<<endl;}

}


#include<bits/stdc++.h>
using namespace std;
long long int val( int a[],int n,int p,int k,long long int dp[])
{

    dp[1]=a[1]; dp[0]=a[0];
    for(int i=2;i<n;i++)
    {
       dp[i]=min(dp[i-2]+a[i],dp[i-1]+a[i]);
    }int res=-1;
    for(int i=0;i<n;i++)
    {
        if(p>=dp[i])
        {
            res=i;
        }
    }
   return res+1;

}
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int n,p,k;
    cin>>n>>p>>k;
 int a[n];
    for(int i=0;i<n;i++)
 cin>>a[i];long long int dp[n];memset(dp,-1,sizeof(dp));sort(a,a+n);
cout<< val(a,n,p,k,dp)<<endl;}

}


#include<bits/stdc++.h>
using namespace std;
int val(int a[],int n,int p,int k,int g)
{
    if(p==0||n==0)
    {
        return 0;
    }
    if(p<a[n-1])
    return 0;
    if(a[n-2]>p&&p>=a[n-1])
    {
        return 1;
    }
    val(a,n-1,p,k,g);
    if(p>=a[n-1])
    {

        return min(n, max(k,1+val(a,n-1,p-a[n-1],k,g)));
    }

 }
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n];
        for(int i=0;i<n;i++)
        {cin>>a[i];}
        sort(a,a+n,greater<int>());int g=n;

        cout<<min(n,val(a,n,p,k,g))<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int val(int a[],int n,int p,int k,int g)
{
    if(p==0||n==0)
    {
        return 0;
    }
    if(p<a[n-1])
    return 0;

    val(a,n-1,p,k,g);
    if(p>=a[n-1])
    {

        return max(k,1+val(a,n-1,p-a[n-1],k,g));
    }

 }
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n];int sum=0;
        for(int i=0;i<n;i++)
        {cin>>a[i];sum=sum+a[i];}
        sort(a,a+n,greater<int>());int g=n;if(a[n-2]>p&&p>=a[n-1]){cout<<"1"<<endl;continue;}

        if(p>=sum)
        cout<<val(a,n,p,k,g)-1<<endl;
        else
        cout<<val(a,n,p,k,g)<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int val(int a[],int n,int p,int k,int g)
{
    if(p==0||n==0)
    {
        return 0;
    }
    if(p<a[n-1])
    return 0;

    val(a,n-1,p,k,g);
    if(p>=a[n-1])
    {

        return max(k,1+val(a,n-1,p-a[n-1],k,g));
    }

 }
int main()
{
    int t;cin>>t;
    while(t--)
    {
        int n,p,k;
        cin>>n>>p>>k;
        int a[n];int sum=0;
        for(int i=0;i<n;i++)
        {cin>>a[i];sum=sum+a[i];}
        sort(a,a+n,greater<int>());int g=n;
        if(p>=sum)
        cout<<val(a,n,p,k,g)-1<<endl;
        else
        cout<<val(a,n,p,k,g)<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
long long int val( int a[],int n,int p,int k,long long int dp[])
{

    dp[1]=a[1]; dp[0]=a[0];
    for(int i=2;i<n;i++)
    {
       dp[i]=min(dp[i-2]+a[i],dp[i-1]+a[i]);
    }int res=-1;
    for(int i=0;i<n;i++)
    {
        if(p>=dp[i])
        {
            res=max(res,i);
        }
    }
   return res+1;

}
int main()
{
    int t;cin>>t;
    while(t--)
    {
    int n,p,k;
    cin>>n>>p>>k;
 int a[n];
    for(int i=0;i<n;i++)
 cin>>a[i];long long int dp[n];memset(dp,-1,sizeof(dp));sort(a,a+n);
cout<< val(a,n,p,k,dp)<<endl;}

}


#include<bits/stdc++.h>

using namespace std;

const int N = 2e5;
const int K = 2e9;

int arr[N];
int n, p, k;

int Cnt(int np, int shift)
{
    int i, j, cnt = 0;
    for(i = k -1 +shift; i < n; i += k)
    {
        if(arr[i] > np)
            break;
        np -= arr[i];
        cnt += k;
    }
    for(j = i -k +1; j < n; j++)
    {
        if(arr[j] > np)
            break;
        np -= arr[j];
        cnt += 1;
    }
    return cnt;
}

bool can(int cnt)
{
    int ans = 0;

    for(int shift = 0; shift < k; shift++)
    {
        if(shift)
        {
            if(arr[shift-1] > p)
                break;
            for(int i = 1; i <= shift; i++)
                ans = max(ans, 1 +Cnt(p - arr[shift -i], shift));
        }
        ans = max(ans, Cnt(p, shift));
    }

    return ans >= cnt;
}
int bs()
{
    int  hi = n;
    int low = 0;
    int ans = 0;

    while(low <= hi)
    {
        int mid = (hi + low)/2;
        if(can(mid))
        {
            ans = mid;
            low = mid +1;
        }
        else
            hi = mid-1;
    }
    return ans;
}
int main()
{
    int t;
    for(cin >> t; t--;)
    {
        cin >> n >> p >> k;
        for(int i = 0; i < n; i++)
            cin >> arr[i];

        sort(arr, arr+n);

        cout << bs() << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

#define iii pair< int, pair<int, int> >
#define cnt frp.first
#define pos frp.second.first
#define mon frp.second.second

const int N = 2e5;
const int K = 2e9;

int n, p, k;
int arr[N];

int dij()
{
    int ans = 0;

    priority_queue< iii, vector<iii>, greater<iii> > que;

    for(int i = 0; i < n; i++)
        que.push({0, {i, p}});

    iii frp, last = {-1, {-1, -1}};

    while(!que.empty())
    {
        frp = que.top(); que.pop();

        if(frp == last)
            continue;
        else
            last = frp;

        if(pos == n)
        {
            ans = max(ans, cnt);
            continue;
        }

        que.push({cnt, {pos +1, mon}});

        if(arr[pos] > mon)
            continue;

        que.push({cnt +1, {pos +1, mon - arr[pos]}});

        if(pos +k <= n)
            que.push({cnt +k, {pos +k, mon - arr[pos]}});
    }

    return ans;
}
int main()
{
    int t;
    for(scanf("%d", &t); t--;)
    {
        scanf("%d%d%d", &n, &p, &k);
        for(int i = 0; i < n; i++)
            scanf("%d", &arr[i]);

        sort(arr, arr+n, greater<int>());

        printf("%d\n", dij());
    }
}


// i couldn't use top down method because p can be up to 2e9
// remember to read the input ranges at first you f**king idiot

#include<bits/stdc++.h>

using namespace std;

int n, p, k;
int arr[200020];

int go(int pos, int money)
{
    if(pos == n || !money)
        return 0;

    if(arr[pos] > money)
        return go(pos +1, money);

    int fAns = 0 + go(pos +1, money);

    int sAns = 1 + go(pos +1, money - arr[pos]);

    int tAns = 0;
    if(pos + k <= n)
        tAns = k + go(pos +k, money - arr[pos]);

    return max(fAns, max(sAns, tAns));
}
int main()
{
    int t;
    for(cin >> t; t--;)
    {
        cin >> n >> p >> k;
        for(int i = 0; i < n; i++)
            cin >> arr[i];

        sort(arr, arr+n, greater<int>());

        cout << go(0, p) << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

const int N = 2e5;
const int K = 2e9;

int arr[N];
int n, p, k;

bool can(int cnt)
{
    int ans = 0;
    int i, j, np = p, Cnt = 0;

    for(int shift : {0, 1})
    {
        if(shift)
        {
            if(arr[0] > p)
                break;
            np = p - arr[0];
            Cnt = 1;
        }

        for(i = k-1+shift; i < n; i += k)
        {
            if(arr[i] > np)
                break;
            np -= arr[i];
            Cnt += k;
        }
        for(j = i-k+1; j < n; j++)
        {
            if(arr[j] > np)
                break;
            np -= arr[j];
            Cnt += 1;
        }
        ans = max(ans, Cnt);
    }

    return ans >= cnt;
}
int bs()
{
    int  hi = n;
    int low = 0;
    int ans = 0;

    while(low <= hi)
    {
        int mid = (hi + low)/2;
        if(can(mid))
        {
            ans = mid;
            low = mid +1;
        }
        else
            hi = mid-1;
    }
    return ans;
}
int main()
{
    int t;
    for(cin >> t; t--;)
    {
        cin >> n >> p >> k;
        for(int i = 0; i < n; i++)
            cin >> arr[i];

        sort(arr, arr+n);

        cout << bs() << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

const int N = 2e5;
const int K = 2e9;

int arr[N];
int n, p, k;

int Cnt(int np, int shift)
{
    int i, j, cnt = 0;
    for(i = k -1 +shift; i < n; i += k)
    {
        if(arr[i] > np)
            break;
        np -= arr[i];
        cnt += k;
    }
    for(j = i -k +1; j < n; j++)
    {
        if(arr[j] > np)
            break;
        np -= arr[j];
        cnt += 1;
    }
    return cnt;
}

bool can(int cnt)
{
    int ans = 0;

    for(int shift = 0; shift < k; shift++)
    {
        if(arr[shift-1] > p)
            break;
        if(shift)
        {
            ans = max(ans, 0 +Cnt(p, shift));
            ans = max(ans, 1 +Cnt(p - arr[shift -1], shift));
        }
        else
            ans = max(ans, 0 +Cnt(p, shift));
    }

    return ans >= cnt;
}
int bs()
{
    int  hi = n;
    int low = 0;
    int ans = 0;

    while(low <= hi)
    {
        int mid = (hi + low)/2;
        if(can(mid))
        {
            ans = mid;
            low = mid +1;
        }
        else
            hi = mid-1;
    }
    return ans;
}
int main()
{
    int t;
    for(cin >> t; t--;)
    {
        cin >> n >> p >> k;
        for(int i = 0; i < n; i++)
            cin >> arr[i];

        sort(arr, arr+n);

        cout << bs() << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;

#define iii pair< int, pair<int, int> >

const int N = 2e5;
const int K = 2e9;

int n, p, k;
int arr[N];

int dij()
{
    int ans = 0;

    priority_queue< iii, vector<iii>, greater<iii> > que;

    for(int i = 0; i < n; i++)
        que.push({0, {i, p}});

    iii last = {-1, {-1, -1}};

    while(!que.empty())
    {
        iii frp = que.top(); que.pop();

        if(frp == last)
            continue;
        else
            last = frp;

        int cnt = frp.first;
        int pos = frp.second.first;
        int mon = frp.second.second;

        if(pos == n)
        {
            ans = max(ans, cnt);
            continue;
        }

        if(pos > n || arr[pos] > mon)
            continue;

        que.push({cnt, {pos +1, mon}});
        que.push({cnt +1, {pos +1, mon - arr[pos]}});

        if(pos +k <= n)
            que.push({cnt +k, {pos +k, mon - arr[pos]}});
    }

    return ans;
}
int main()
{
    int t;
    for(cin >> t; t--;)
    {
        cin >> n >> p >> k;
        for(int i = 0; i < n; i++)
            cin >> arr[i];

        sort(arr, arr+n, greater<int>());

        cout << dij() << endl;
    }
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll tp=p;
ll ans=0;
ll i=0;
while(i<n)
{
if(i+3<=n-1)
{
  if(a[i+3]+a[i+1]<=p)
  {
    ans+=4;
    p-=a[i+1]+a[i+3];

    i=i+4;
  }
  else
  if(a[i]+a[i+2]<=p)
  {
    ans+=3;
    p-=a[i+2]+a[i];

    i=i+3;

  }
  else
  if(a[i+1]<=p)
  {
    ans+=2;
    p-=a[i+1];

    i=i+2;
  }
  else
  if(a[i]<=p)
  {
    ans+=1;
    p-=a[i];

    i=i+1;
  }
  else
  i=n;

}
else{
  if(i+2<=n-1)
  {
    if(a[i+2]+a[i]<=p)
    {
      ans+=3;
      p-=a[i+2]+a[i];
      i=i+3;
    }
    else
    if(a[i+1]<=p)
    {
      ans+=2;
      p-=a[i+1];
      i=i+2;
    }
    else
    if(a[i]<=p)
    {
      ans++;
      p-=a[i];
      i++;
    }
    else
    i=n;
  }
  else
  {
    if(i==n-2)
    {
      if(a[i+1]<=p)
      {
        ans+=2;
        i=n;
      }
      else
      if(a[n-2]<=p)
      {
        ans++;
        i=n;

      }
      else
      i=n;
    }
    else
    {
      if(a[n-1]<=p)
      {
        ans++;
        i=n;
      }
      else
      i=n;
    }
  }
}
}
cout<<ans<<'\n';
}
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll tp=p;
ll ans=0;
ll i=0;
while(i<n)
{
  if(i+2<=n-1)
  {
    if(p<a[i])
    i=n;
    else
    if(a[i]<=p&&p<a[i+1])
    {
      ans++;
      i=n;
    }
    else
    if(a[i+1]<=p&&p<a[i+2])
    {
      ans+=2;
      i=n;
    }
    else
    {
      if(i+3<=n-1)
      {
        if(a[i+1]+a[i+3]<=p)
        {
          ans+=4;
          i=i+4;
          p-=a[i+1]+a[i+3];
        }
        else
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          i=n;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
      else
      {
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          i=n;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
    }
  }
  else
  {
    if(i==n-2)
    {
      if(p>=a[i+1])
      {
        ans+=2;
        i=n;
      }
      else
      if(p>=a[i])
      {
        ans++;
        i=n;
      }
      else
      i=n;

    }
    else
    {
      if(p>=a[n-1])
      {
        ans++;
        i=n;
      }
      else
      i=n;
    }
  }
}
cout<<ans<<'\n';
}
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll sum[n];
sum[0]=a[0];
sum[1]=a[1];
REP(i,2,n-1)
sum[i]=sum[i-2]+a[i];

ll i=0;
while(sum[i]<=p&&i<n)
i++;

cout<<i<<'\n';
}
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll tp=p;
ll ans=0;
ll i=0;
while(i<n)
{
  if(i+2<=n-1)
  {
    if(p<a[i])
    i=n;
    else
    if(a[i]<=p&&p<a[i+1])
    {
      ans++;
      i=n;
    }
    else
    if(a[i+1]<=p&&p<a[i+2])
    {
      ans+=2;
      i=n;
    }
    else
    {
      if(i+4<=n-1)
      {
        if(a[i+1]+a[i+3]<=p)
        {
          ans+=4;
          i=i+5;
          p-=a[i+1]+a[i+3];
        }
        else
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          i=n;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
      else
      {
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          i=n;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
    }
  }
  else
  {
    if(i==n-2)
    {
      if(p>=a[i+1])
      {
        ans+=2;
        i=n;
      }
      else
      if(p>=a[i])
      {
        ans++;
        i=n;
      }
      else
      i=n;

    }
    else
    {
      if(p>=a[n-1])
      {
        ans++;
        i=n;
      }
      else
      i=n;
    }
  }
}
cout<<ans<<'\n';
}
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll tp=p;
ll ans=0;
ll i=0;
while(i<n)
{
if(i+3<=n-1)
{
  if(a[i+3]+a[i+1]<=p)
  {
    ans+=4;
    i=i+4;
    p-=a[i+1]+a[i+3];
  }
  else
  if(a[i]+a[i+2]<=p)
  {
    ans+=3;
    i=i+3;
    p-=a[i+2]+a[i];
  }
  else
  if(a[i+1]<=p)
  {
    ans+=2;
    i=i+2;
    p-=a[i+1];
  }
  else
  if(a[i]<=p)
  {
    ans+=1;
    i=i+1;
    p-=a[i];
  }
  else
  i++;

}
else{
  if(i+2<=n-1)
  {
    if(a[i+2]+a[i]<=p)
    {
      ans+=3;
      i=n;
    }
    else
    if(a[i+1]<=p)
    {
      ans+=2;
      i=i+2;
      p-=a[i+1];
    }
    else
    if(a[i]<=p)
    {
      ans++;
      i++;
      p-=a[i];
    }
    else
    i=n;
  }
  else
  {
    if(i==n-2)
    {
      if(a[i+1]<=p)
      {
        ans+=2;
        i=n;
      }
      else
      if(a[n-2]<=p)
      {
        ans++;
        i=n;

      }
      else
      i=n;
    }
    else
    {
      if(a[n-1]<=p)
      {
        ans++;
        i=n;
      }
      else
      i=n;
    }
  }
}
}
cout<<ans<<'\n';
}
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll tp=p;
ll ans=0;
ll i=0;
while(i<n)
{
if(i+3<=n-1)
{
  if(a[i+3]+a[i+1]<=p)
  {
    ans+=4;
    p-=a[i+1]+a[i+3];

    i=i+4;
  }
  else
  if(a[i]+a[i+2]<=p)
  {
    ans+=3;
    p-=a[i+2]+a[i];

    i=i+3;

  }
  else
  if(a[i+1]<=p)
  {
    ans+=2;
    p-=a[i+1];

    i=i+2;
  }
  else
  if(a[i]<=p)
  {
    ans+=1;
    p-=a[i];

    i=i+1;
  }
  else
  i=n;

}
else{
  if(i+2<=n-1)
  {
    if(a[i+2]+a[i]<=p)
    {
      ans+=3;
      i=i+3;
    }
    else
    if(a[i+1]<=p)
    {
      ans+=2;
      i=i+2;
      p-=a[i+1];
    }
    else
    if(a[i]<=p)
    {
      ans++;
      i++;
      p-=a[i];
    }
    else
    i=n;
  }
  else
  {
    if(i==n-2)
    {
      if(a[i+1]<=p)
      {
        ans+=2;
        i=n;
      }
      else
      if(a[n-2]<=p)
      {
        ans++;
        i=n;

      }
      else
      i=n;
    }
    else
    {
      if(a[n-1]<=p)
      {
        ans++;
        i=n;
      }
      else
      i=n;
    }
  }
}
}
cout<<ans<<'\n';
}
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll tp=p;
ll ans=0;
ll i=0;
while(i<n)
{
  if(i+2<=n-1)
  {
    if(p<a[i])
    i=n;
    else
    if(a[i]<=p&&p<a[i+1])
    {
      ans++;
      i=n;
    }
    else
    if(a[i+1]<=p&&p<a[i+2])
    {
      ans+=2;
      i=n;
    }
    else
    {
      if(i+3<=n-1)
      {
        if(a[i+1]+a[i+3]<=p)
        {
          ans+=4;
          i=i+5;
          p-=a[i+1]+a[i+3];
        }
        else
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          i=n;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
      else
      {
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          i=n;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
    }
  }
  else
  {
    if(i==n-2)
    {
      if(p>=a[i+1])
      {
        ans+=2;
        i=n;
      }
      else
      if(p>=a[i])
      {
        ans++;
        i=n;
      }
      else
      i=n;

    }
    else
    {
      if(p>=a[n-1])
      {
        ans++;
        i=n;
      }
      else
      i=n;
    }
  }
}
cout<<ans<<'\n';
}
}


#include<bits/stdc++.h>

using namespace std;
#define IOS { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }

typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
#define REP(i,a,b) for(ll i=a;i<=b;++i)
#define REV(i,a,b) for(ll i=a;i>=b;i--)
#define pll pair<ll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
ll mod=1000000007;

ll min(ll a,ll b)
{
  if(a>b)
  return b;
  return a;
}
ll max(ll a,ll b)
{
  if(a<b)
  return b;
  return a;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}

ll diff(ll a,ll b)
{
  if(a>b)
  return a-b;
  return b-a;
}
void swap(ll *a,ll *b)
{
  ll t=*a;
  *a=*b;
  *b=t;
}

 ll lcm(ll a, ll b)
  {
    if(a==0)
    return b;
    if(b==0)
    return a;
     return (a*b)/gcd(a, b);
  }

int main()
{
ll t;
cin>>t;
while(t--)
{
ll n,p,k;
cin>>n>>p>>k;
ll a[n];
REP(i,0,n-1)
cin>>a[i];

sort(a,a+n);
ll tp=p;
ll ans=0;
ll i=0;
while(i<n)
{
  if(i+2<=n-1)
  {
    if(p<a[i])
    i=n;
    else
    if(a[i]<=p&&p<a[i+1])
    {
      ans++;
      i=n;
    }
    else
    if(a[i+1]<=p&&p<a[i+2])
    {
      ans+=2;
      i=n;
    }
    else
    {
      if(i+3<=n-1)
      {
        if(a[i+1]+a[i+3]<=p)
        {
          ans+=4;
          i=i+4;
          p-=a[i+1]+a[i+3];
        }
        else
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          p-=a[i]+a[i+2];
          i=i+3;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
      else
      {
        if(p>=a[i]+a[i+2])
        {
          ans+=3;
          i=n;
        }
        else
        {
          ans+=2;
          i=n;
        }
      }
    }
  }
  else
  {
    if(i==n-2)
    {
      if(p>=a[i+1])
      {
        ans+=2;
        i=n;
      }
      else
      if(p>=a[i])
      {
        ans++;
        i=n;
      }
      else
      i=n;

    }
    else
    {
      if(p>=a[n-1])
      {
        ans++;
        i=n;
      }
      else
      i=n;
    }
  }
}
cout<<ans<<'\n';
}
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
        if(n%2==0){
            ans=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans++;
                        break;
                    }
                }
            }
        }
        else{
            ans=1;
            long long int sum=arr[0];
            for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans+=2;
                }
                else{
                    if(sum+arr[i]-arr[0]<=k){
                        sum+=arr[i]-arr[0];
                        ans++;
                        break;
                    }
                    if(sum+arr[i-1]-arr[0]<=k){
                        sum+=arr[i-1]-arr[0];
                        ans++;
                        break;
                    }
                }

            }

        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
        if(n%2==0){
            ans=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans++;
                        break;
                    }
                }
            }
        }
        else{
            if(arr[0]<=k){
                ans=1;
                long long int sum=arr[0];
                for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans+=2;
                }
                else{
                    if(sum+arr[i]-arr[0]<=k){
                        sum+=arr[i]-arr[0];
                        ans++;
                        break;
                    }
                    else if(sum+arr[i-1]-arr[0]<=k){
                        sum+=arr[i-1]-arr[0];
                        ans++;
                        break;
                    }
                }

               }
            }
            else{
                ans=0;
            }

        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
        if(n%2==0){
            ans=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans++;
                        break;
                    }
                }
            }
        }
        else{
                ans=0;
                long long int sum=0;
                for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans++;
                        break;
                    }
                }

               }
               if(sum+arr[0]<=k){
                   ans++;
               }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
        if(n%2==0){
            long long int ans1=0;
            long long int ans2=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans1+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans1++;
                        break;
                    }
                }
            }
            sum=0;
                int ctr=0;
                for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans2+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans2+=2;
                        ctr=1;
                        break;
                    }
                }

               }
               if(sum+arr[0]<=k && ctr==0){
                   ans2++;
               }
               ans=max(ans1,ans2);

        }
        else{
                ans=0;
                int ctr=0;
                long long int sum=0;
                for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans+=2;
                        ctr=1;
                        break;
                    }
                }

               }
               if(sum+arr[0]<=k && ctr==0){
                   ans++;
               }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
            long long int ans1=0;
            long long int ans2=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans1+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans1++;
                        break;
                    }
                }
            }
            sum=0;
                int ctr=0;
                for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans2+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans2+=2;
                        ctr=1;
                        break;
                    }
                }

               }
               if(sum+arr[0]<=k && ctr==0){
                   ans2++;
               }
               ans=max(ans1,ans2);
        cout<<ans<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
        if(n%2==0){
            ans=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans++;
                        break;
                    }
                }
            }
        }
        else{
            if(arr[0]<=k){
                ans=1;
                long long int sum=arr[0];
                for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans+=2;
                }
                else{
                    if(sum+arr[i]-arr[0]<=k){
                        sum+=arr[i]-arr[0];
                        ans++;
                        break;
                    }
                    if(sum+arr[i-1]-arr[0]<=k){
                        sum+=arr[i-1]-arr[0];
                        ans++;
                        break;
                    }
                }

               }
            }
            else{
                ans=0;
            }

        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
        if(n%2==0){
            ans=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans+=2;
                }
                if(sum+arr[i]>k){
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans++;
                        break;
                    }
                }
            }
        }
        else{
            ans=1;
            long long int sum=arr[0];
            for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans+=2;
                }
                if(sum+arr[i]>k){
                    if(sum+arr[i]-arr[0]<=k){
                        sum+=arr[i]-arr[0];
                        ans++;
                        break;
                    }
                    if(sum+arr[i-1]-arr[0]<=k){
                        sum+=arr[i-1]-arr[0];
                        ans++;
                        break;
                    }
                }

            }

        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int T;
    cin>>T;
    while(T--){
        long long int n,k,t;
        cin>>n>>k>>t;
        int arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        sort(arr,arr+n);
        long long int ans;
        if(n%2==0){
            ans=0;
            long long int sum=0;
            for(int i=1;i<n;i=i+2){
                if(sum+arr[i]<=k){
                    sum+=arr[i];
                    ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans++;
                        break;
                    }
                }
            }
        }
        else{
                ans=0;
                int ctr=0;
                long long int sum=0;
                for(int i=2;i<n;i+=2){
                if(sum+arr[i]<=k){
                   sum+=arr[i];
                   ans+=2;
                }
                else{
                    if(sum+arr[i-1]<=k){
                        sum+=arr[i-1];
                        ans+=2;
                        ctr=1;
                        break;
                    }
                }

               }
               if(sum+arr[0]<=k && ctr==0){
                   ans++;
               }
        }
        cout<<ans<<endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[20501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (i = 1; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = ans;

        ans = 0;

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

                    break;
                }
            }

            p -= arr[i];

            ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= p){
                        ans++;

                        break;
                    }
                }
            }
        }

        mx = max(ans, mx);

        cout << mx << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[10501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr, arr + n);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (j = 1; j <= 5; j++){
            mx = max(ans, mx);

            ans = 0;

            sum = p;

            for (i = j; i <= n; i += 2){
                if (arr[i] > sum){
                    if (arr[i - 1] > sum) break;
                    else {
                        ans++;

                        break;
                    }
                }

                sum -= arr[i];

                if (i == 1) ans++;
                else ans += 2;

                if (i + 2 > n){
                    if (i + 1 == n){
                        if (arr[i + 1] <= sum){
                            ans++;

                            break;
                        }
                        else break;
                    }
                }
            }
        }

        cout << mx << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[10501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (j = 1; j <= 3; j++){
            mx = max(ans, mx);

            ans = 0;

            sum = p;

            for (i = j; i <= n; i += 2){
                if (arr[i] > sum){
                    if (arr[i - 1] > sum) break;
                    else {
                        ans++;

                        break;
                    }
                }

                sum -= arr[i];

                if (i == 1) ans++;
                else ans += 2;

                if (i + 2 > n){
                    if (i + 1 == n){
                        if (arr[i + 1] <= sum){
                            ans++;

                            break;
                        }
                        else break;
                    }
                }
            }
        }

        cout << mx << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[10501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (i = 1; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = ans;

        ans = 0;

        sum = p;

        for (i = 2; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = max(ans, mx);

        ans = 0;

        sum = p;

        for (i = n; i >= 1; i -= 2){
            if (arr[i] > sum){
                continue;
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;
        }

        mx = max(ans, mx);

        ans = 0;

        sum = p;

        for (i = n - 1; i >= 1; i -= 2){
            if (arr[i] > sum){
                continue;
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;
        }

        mx = max(ans, mx);

        cout << mx << endl;

        mx = 0;

        ans = 0;

        sum = 0;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[10501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (j = 1; j <= 5; j++){
            mx = max(ans, mx);

            ans = 0;

            sum = p;

            for (i = j; i <= n; i += 2){
                if (arr[i] > sum){
                    if (arr[i - 1] > sum) break;
                    else {
                        ans++;

                        break;
                    }
                }

                sum -= arr[i];

                if (i == 1) ans++;
                else ans += 2;

                if (i + 2 > n){
                    if (i + 1 == n){
                        if (arr[i + 1] <= sum){
                            ans++;

                            break;
                        }
                        else break;
                    }
                }
            }
        }

        cout << mx << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[10501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (i = 1; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 == n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = ans;

        ans = 0;

        sum = p;

        for (i = 2; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 == n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = max(ans, mx);

        cout << mx << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[10501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (i = 1; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = ans;

        ans = 0;

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

                    break;
                }
            }

            p -= arr[i];

            ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= p){
                        ans++;

                        break;
                    }
                }
            }
        }

        mx = max(ans, mx);

        cout << mx << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[200001], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (i = 1; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = ans;

        ans = 0;

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

                    break;
                }
            }

            p -= arr[i];

            ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= p){
                        ans++;

                        break;
                    }
                }
            }
        }

        mx = max(ans, mx);

        cout << mx << endl;
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <algorithm>

#define endl '\n'
#define ll long long
#define ld long double

#define y1 abc

using namespace std;

ll q, n, p, k, arr[10501], i, j, ans, sum, mx;

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> q;

    while (q--){
        cin >> n >> p >> k;

        for (i = 1; i <= n; i++){
            cin >> arr[i];
        }

        sort(arr + 1, arr + n + 1);

        if (arr[1] > p){
            cout << "0" << endl;

            continue;
        }

        sum = p;

        mx = 0;

        ans = 0;

        for (i = 1; i <= n; i += 2){
            if (arr[i] > sum){
                if (arr[i - 1] > sum) break;
                else {
                    ans++;

                    break;
                }
            }

            sum -= arr[i];

            if (i == 1) ans++;
            else ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= sum){
                        ans++;

                        break;
                    }
                    else break;
                }
            }
        }

        mx = ans;

        ans = 0;

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

                    break;
                }
            }

            p -= arr[i];

            ans += 2;

            if (i + 2 > n){
                if (i + 1 <= n){
                    if (arr[i + 1] <= p){
                        ans++;

                        break;
                    }
                }
            }
        }

        mx = max(ans, mx);

        cout << mx << endl;

        for (i = 1; i <= n; i++){
            arr[i] = 0;
        }
    }

    return 0;
}


#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef vector<long long> vi;
typedef pair<long long,long long> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define loop(i, len) for (long long i = 0; i < len; ++i)
#define loopr(i, len) for (long long i = len; i >=0; --i)

#define LOCAL 0

ll a[1000000];
ll pref[1000000];

int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
      ll n,c,k;
      cin>>n>>c>>k;
      loop(i,n)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      loop(i,n)
      {
          if(i<k-1) {
              pref[i + 1] = a[i] + pref[i];
          }
          else  pref[i + 1] = a[i]+pref[i-k+1];

      }
      ll co=c;
      ll cnt=0,ans=0,ans2=0;
      if(co-a[k-1]==0)ans=k;
      else if(co-a[k-1]>0) {

          ans=k;
          for(ll i=k;i<n;i++) {
              co -= a[i] + pref[i - k + 1];
              if (co >= 0) {
                  co = c;
                  ans = i + 1;
              } else {break;}

          }
      } else
      {
          loop(i,k)
          {
              if(co-a[i]>=0)ans2+=1,co-=a[i];
          }
      }
  cout<<max(ans,ans2)<<endl;
  }
}


#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef vector<long long> vi;
typedef pair<long long,long long> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define loop(i, len) for (long long i = 0; i < len; ++i)
#define loopr(i, len) for (long long i = len; i >=0; --i)

#define LOCAL 0

ll a[10001];
ll pref[10001];

int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
      ll n,c,k;
      cin>>n>>c>>k;
      loop(i,n)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      loop(i,n)
      {
       pref[i+1]=a[i]+pref[i];
      }
      ll co=c;
      ll cnt=0,ans=0,ans2=0;
      loop(i,n)
      {
          if(i>=k) {
              co -= a[i] + pref[i - k + 1];
              if(co<0)
              {
                  co=c;
                  for(ll j=1;j<i-k+2;j++){
                      co-=a[i]+pref[j];
                      if(co>=0)
                      {
                          co=c;
                          ans2=j+k;
                      }
                      else {co=-1;break;};

                  }

              }
          }
          else co-=a[i];
      if(co>=0)
      {
          co=c;
          ans=i+1;
      }
      else break;

      }
  cout<<max(ans,ans2)<<endl;
  }
}


#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef vector<long long> vi;
typedef pair<long long,long long> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define loop(i, len) for (long long i = 0; i < len; ++i)
#define loopr(i, len) for (long long i = len; i >=0; --i)

#define LOCAL 0

ll a[10001];
ll pref[10001];

int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
      ll n,c,k;
      cin>>n>>c>>k;
      loop(i,n)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      loop(i,n)
      {
          if(i<k-1) {
              pref[i + 1] = a[i] + pref[i];
          }
          else  pref[i + 1] = a[i]+pref[i-k+1];

      }
      ll co=c;
      ll cnt=0,ans=0,ans2=0;
      if(co-a[k-1]==0)ans=k;
      else if(co-a[k-1]>0) {

          ans=k;
          for(ll i=k;i<n;i++) {
              co -= a[i] + pref[i - k + 1];
              if (co >= 0) {
                  co = c;
                  ans = i + 1;
              } else {break;}

          }
      } else
      {
          loop(i,k)
          {
              if(co-a[i]>=0)ans2+=1,co-=a[i];
          }
      }
  cout<<max(ans,ans2)<<endl;
  }
}


#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef vector<long long> vi;
typedef pair<long long,long long> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define loop(i, len) for (long long i = 0; i < len; ++i)
#define loopr(i, len) for (long long i = len; i >=0; --i)

#define LOCAL 0

ll a[10001];
ll pref[10001];

int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
      ll n,c,k;
      cin>>n>>c>>k;
      loop(i,n)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      loop(i,n)
      {
       pref[i+1]=a[i]+pref[i];
      }
      ll co=c;
      ll cnt=0,ans=0,ans2=0;
      if(co-a[k-1]>=0) {

          for(ll i=k-1;i<n;i++) {
              if (i >= k) { co -= a[i] + pref[i - k + 1]; }
              else co -= a[i];
              if (co >= 0) {
                  co = c;
                  ans = i + 1;
              } else break;

          }
      } else
      {
          loop(i,k-1)
          {
              if(co-a[i]>=0)ans2+=1,co-=a[i];
          }
      }
  cout<<max(ans,ans2)<<endl;
  }
}


#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef vector<long long> vi;
typedef pair<long long,long long> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define loop(i, len) for (long long i = 0; i < len; ++i)
#define loopr(i, len) for (long long i = len; i >=0; --i)

#define LOCAL 0

ll a[10001];
ll pref[10001];

int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
      ll n,c,k;
      cin>>n>>c>>k;
      loop(i,n)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      loop(i,n)
      {
          if(i+1%k!=0) {
              pref[i + 1] = a[i] + pref[i];
          }
          else  pref[i + 1] = a[i]+pref[i-k+1];

      }
      ll co=c;
      ll cnt=0,ans=0,ans2=0;
      if(co-a[k-1]==0)ans=k;
      else if(co-a[k-1]>0) {

          ans=k;
          for(ll i=k;i<n;i++) {
              co -= a[i] + pref[i - k + 1];
              if (co >= 0) {
                  co = c;
                  ans = i + 1;
              } else {break;}

          }
      } else
      {
          loop(i,k)
          {
              if(co-a[i]>=0)ans2+=1,co-=a[i];
          }
      }
  cout<<max(ans,ans2)<<endl;
  }
}


#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef vector<long long> vi;
typedef pair<long long,long long> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define loop(i, len) for (long long i = 0; i < len; ++i)
#define loopr(i, len) for (long long i = len; i >=0; --i)

#define LOCAL 0

ll a[10001];
ll pref[10001];

int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
      ll n,c,k;
      cin>>n>>c>>k;
      loop(i,n)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      loop(i,n)
      {
       pref[i+1]=a[i]+pref[i];
      }
      ll co=c;
      ll cnt=0,ans=0;
      loop(i,n)
      {
          if(i>=k) {
              co -= a[i] + pref[i - k + 1];
              if(co<0)
              {
                  ans=max(i,k);
                  break;
              }
          }
          else co-=a[i];
      if(co>=0)
      {
          co=c;
          ans=i+1;
      }
      else break;

      }
  cout<<ans<<endl;
  }
}


#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
typedef vector<long long> vi;
typedef pair<long long,long long> pi;
#define F first
#define S second
#define PB push_back
#define MP make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define loop(i, len) for (long long i = 0; i < len; ++i)
#define loopr(i, len) for (long long i = len; i >=0; --i)

#define LOCAL 0

ll a[10001];
ll pref[10001];

int main()
{
  ll t;
  cin>>t;
  while(t--)
  {
      ll n,c,k;
      cin>>n>>c>>k;
      loop(i,n)
      {
          cin>>a[i];
      }
      sort(a,a+n);
      loop(i,n)
      {
       pref[i+1]=a[i]+pref[i];
      }
      ll co=c;
      ll cnt=0,ans=0,ans2=0;
      if(co-a[k-1]>=0) {

          loop(i, n) {
              if (i >= k) { co -= a[i] + pref[i - k + 1]; }
              else co -= a[i];
              if (co >= 0) {
                  co = c;
                  ans = i + 1;
              } else break;

          }
      } else
      {
          loop(i,k-1)
          {
              if(co-a[i]>=0)ans2+=1,co-=a[i];
          }
      }
  cout<<max(ans,ans2)<<endl;
  }
}