import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner scan = new Scanner(System.in);
int tc = scan.nextInt();
while(tc!=0) {
int nos = scan.nextInt();
int[] x = new int[nos];
for(int i=0;i<nos;i++) {
x[i] = scan.nextInt();
}
int[] y = new int[nos];
for(int i=0;i<nos;i++) {
y[i] = scan.nextInt();
}
System.out.println(Work(x,y));
tc--;
}
}
private static int Work(int[] x, int[] y) {
int ans =0;
for(int i=0;i<x.length;i++) {
for(int j=i;j<y.length;j++) {
ans +=(x[i]-x[j])*(Math.max(y[i], y[j]));
}
}
return Math.abs(ans);
}
}
// ans come wrong on hackerblock but true come on my Ids