/*
**************
***HDU 2602***
**************
*/
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
#define rep(i,j,k)for(i=j;i<k;i++)
#define per(i,j,k)for(i=j;i>k;i--)
#define MS(x,y)memset(x,y,sizeof(x))
#define max(a,b) a>b?a:b
#define min(a,b) a<b?a:b
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef long long LL;
const int INF=0x7ffffff;
#define lson rt<<1, l, m
#define rson rt<<1|1, m+1, r
const int M=1000;
int dp[M][M];
int i,j,k,n,m,v;
int val[M],vol[M];
int main()
{
int T;
scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&v);
for(i=1;i<=n;i++)
scanf("%d",&val[i]);
for(i=1;i<=n;i++)
scanf("%d",&vol[i]);
MS(dp,0);
for(i=1;i<=n;i++)
for(j=0;j<=v;j++){
if(vol[i]<=j)
dp[i][j]=max(dp[i-1][j],dp[i-1][j-vol[i]]+val[i]);
else dp[i][j]=dp[i-1][j];
}
printf("%d\n",dp[n][v]);
}
return 0;
}