import java.util.;
import java.lang.;
import java.io.*;
/* Name of the class has to be “Main” only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t>0)
{ int N=sc.nextInt();
int alice []=new int[N];
int bob[]=new int[N];
for(int i=0;i<N;i++)
{
alice[i]=sc.nextInt();
}
for(int i=0;i<N;i++)
{
bob[i]=sc.nextInt();
}
work(alice,bob,N);
t--;
}
}
public static void work(int alice[],int bob[],int N)
{
int wtp =0;
for(int i=0;i<N;i++)
{
if(alice[i]==bob[i])
{
wtp=wtp+alice[i];
}
}
System.out.println(wtp);
}
}