import java.util.Arrays;

import java.util.*;
public class Main {
    public static void main (String[]args)throws Exception{
        Scanner sc = new Scanner (System.in);

       
        int []A;int []B;
        
        int cases = Integer.parseInt(sc.nextLine());
        String[] men,finall,women;
        String result="";
        
        
        int couples,sum=0,a,b,positionA=0,positionB=0,i=0;
        
        
        for (i=0;i<cases;i++){
            couples = Integer.parseInt(sc.nextLine());
            A = new int [couples];
            B = new int [couples];
            men = sc.nextLine().split(" ");
            women = sc.nextLine().split(" ");
            for(int c=0;c<couples;c++){
                A[c]=Integer.parseInt(men[c]);
                B[c]=Integer.parseInt(women[c]);
            }
            Arrays.sort(A);
            Arrays.sort(B);
            
            for(int c=0;c<couples;c++){
                sum=sum + A[c]*B[c];
            }
            System.out.println(sum);
            sum = 0;
            
        }
    }
}
