#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int v[2000],c[2000],ans,n,m,maxl;
void dfs(int loc,int sum,int val,int get)
{
if(n-loc<m-get)
{
return;
}
if(sum>maxl)
{
return;
}
if(get==m&&sum<=maxl)
{
ans=max(ans,val);
return;
}
dfs(loc+1,sum,val,get);
dfs(loc+1,sum+c[loc+1],val+v[loc+1],get+1);
}
int main()
{
int cases;
scanf("%d",&cases);
while(cases--)
{
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d%d",&v[i],&c[i]);
}
ans=0;
scanf("%d",&maxl);
dfs(0,0,0,0);
printf("%d\n",ans);
}
return 0;
}
蒟蒻的自我拯救。。。