import java.util.*;

public class Eat {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		for (int T = scan.nextInt(), N, M; T-- > 0; ){
			int[] A = new int[N = scan.nextInt()];
			int[] B = new int[M = scan.nextInt()];
			for (int i=0; i<N; i++) A[i] = scan.nextInt();
			for (int i=0; i<M; i++) B[i] = scan.nextInt();
			Arrays.sort(A);
			Arrays.sort(B);

			int total = 0;
			while (N>0 && M>0){
				if (A[N-1] > B[M-1]){
					total += M;
					N--;
				} else {
					M--;
				}
			}
			System.out.println(total);
		}
	}
}