#include <bits/stdc++.h>
using namespace std;
#define PP pair<int,int>
int n,target;
int cost[102], weight[102];
int CAP;
pair<int,int> Knap(int i,int w)
{
if(i==n+1) return make_pair(0,w);
pair<int,int> profit1, profit2;
if(w+weight[i]<=CAP) {
pair<int,int> tmp = Knap(i+1, w + weight[i]);
profit1 = make_pair(tmp.first+cost[i], tmp.second);
}
else
profit1 = make_pair(0,0);
profit2=Knap(i+1,w);
return max(profit1, profit2);
}
int main()
{
int t;
cin>>t;
while(t--)
{
cin>>n;
cin>>CAP;
for(int i=1; i<=n; i++)
{
scanf("%d %d",&weight[i],&cost[i]);
}
pair<int,int>P;
P=Knap(1,0);
cout<<P.first<<" "<<P.second<<endl;
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBQUCBwYWlyPGludCxpbnQ+CmludCBuLHRhcmdldDsKaW50IGNvc3RbMTAyXSwgd2VpZ2h0WzEwMl07CmludCBDQVA7CgpwYWlyPGludCxpbnQ+IEtuYXAoaW50IGksaW50IHcpCnsKICAgIGlmKGk9PW4rMSkgcmV0dXJuIG1ha2VfcGFpcigwLHcpOwogICAgcGFpcjxpbnQsaW50PiBwcm9maXQxLCBwcm9maXQyOwoKICAgIGlmKHcrd2VpZ2h0W2ldPD1DQVApIHsKICAgICAgICBwYWlyPGludCxpbnQ+IHRtcCA9IEtuYXAoaSsxLCB3ICsgd2VpZ2h0W2ldKTsKICAgICAgICBwcm9maXQxID0gbWFrZV9wYWlyKHRtcC5maXJzdCtjb3N0W2ldLCB0bXAuc2Vjb25kKTsKICAgIH0KICAgIGVsc2UKICAgICAgICBwcm9maXQxID0gbWFrZV9wYWlyKDAsMCk7CgogICAgcHJvZml0Mj1LbmFwKGkrMSx3KTsKICAgIHJldHVybiBtYXgocHJvZml0MSwgcHJvZml0Mik7Cn0KCmludCBtYWluKCkKewogICAgaW50IHQ7CiAgICBjaW4+PnQ7CiAgICB3a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