#include <bits/stdc++.h>//please use C++ compiler
#define maxn 1005
//obviously 0-1bags
int main()
{
int T,n,V,i,j,dp[maxn],w[maxn],v[maxn];
scanf("%d",&T);
while(T--)
{
memset(dp,0,sizeof(dp));
scanf("%d%d",&n,&V);
for(i=0; i<n; i++)
scanf("%d",&w[i]);
for(i=0; i<n; i++)
scanf("%d",&v[i]);
for(i=0; i<n; i++)
for(j=V; j>=v[i]; j--)
dp[j]=dp[j]>dp[j-v[i]]+w[i]?dp[j]:dp[j-v[i]]+w[i];
printf("%d\n",dp[V]);
}
return 0;
}