#include<stdio.h>
#include<string.h>
#include<math.h>
long my_max(long x,long y){return x>y?x:y;}
long value[1005],weight[1005];
long dp[1005][1005];
int main()
{
int T,i,j,n,v;
scanf("%d",&T);
while(T--)
{
memset(dp,0,sizeof(dp));
memset(value,0,sizeof(value));
memset(weight,0,sizeof(weight));
scanf("%d %d",&n,&v);
for(i=1;i<=n;i++)
scanf("%ld",&value[i]);
for(i=1;i<=n;i++)
scanf("%ld",&weight[i]);
for(i=1;i<=n;i++)
{
for(j=0;j<=v;j++)//j是从0开始,不是从1开始
{
dp[i][j]=dp[i-1][j];
if(weight[i]<=j)
{
dp[i][j]=my_max(dp[i][j],dp[i-1][j-weight[i]]+value[i]);
}
}
}
printf("%ld\n",dp[n][v]);
}
return 0;
}