import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int a =sc.nextInt();
while(a-->0) {
int x,y;x=sc.nextInt();y=sc.nextInt();
int xx[]=new int[x];int yy[]=new int [x];
for (int i = 0; i < xx.length; i++)
{
xx[i]=sc.nextInt();
}
for (int i = 0; i < yy.length; i++)
{
yy[i]=sc.nextInt();
}
///
int dp[]=new int[y+1];
for (int i = 0; i < xx.length; i++)
{
for (int j =y;j>=yy[i];j--)
{
dp[j]=Math.max(dp[j], dp[j-yy[i]]+xx[i]);
}
}
System.out.println(dp[y]);
}
}
}