import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int T = kb.nextInt();
for (int t = 0; t < T; t++) {
int N = kb.nextInt();
int M = kb.nextInt();
int[] A = new int[N];
int[] B = new int[M];
for (int i = 0; i < N; i++) {
A[i] = kb.nextInt();
}
for (int i = 0; i < M; i++) {
B[i] = kb.nextInt();
}
Arrays.sort(B);
int result = 0;
for (int i = 0; i < N; i++) {
result += binarySearch(B, A[i]);
}
System.out.println(result);
}
}
static int binarySearch(int[] B, int x) {
int left = 0;
int right = B.length - 1;
int count = 0;
while (left <= right) {
int mid = (left + right) / 2;
if (B[mid] < x) {
count = mid + 1;
left = mid + 1;
} else {
right = mid - 1;
}
}
return count;
}
}