// Arup Guha
// 3/12/2014
// Solution to 2014 FHSPS Playoff Problem: The Wolf of Wall Street(wolf)

import java.util.*;

public class wolf {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=0; loop<numCases; loop++) {

			// Read in the data.
			int n = stdin.nextInt();
			if (n > 10) System.out.println("ERROR!!!");
			int[] wagers = new int[n];
			for (int i=0; i<n; i++)
				wagers[i] = stdin.nextInt();

			double[] prob = new double[n];
			for (int i=0; i<n; i++)
				prob[i] = stdin.nextDouble();

			// Greedy works here - match worst bets with least wagers.
			Arrays.sort(wagers);
			Arrays.sort(prob);

			// Our expectation is simply p*w - (1-p)*w = (2p - 1)*w.
			double money = 0;
			for (int i=0; i<n; i++)
				money += ((2*prob[i]-1)*wagers[i]);

			// Print result.
			System.out.printf("%.2f\n", money);
		}
	}
}