import java.util.Scanner;
import java.util.Arrays;

class solution {
	private static int advance(String[] A, int pos) {
		pos++;
		while (pos < A.length && A[pos].equals(A[pos-1])) pos++;
		return pos;
	}
	private static int sizeInter(String[] A, String[] B) {
		Arrays.sort(A);
		Arrays.sort(B);
		int posA = 0;
		int posB = 0;
		int ans = 0;
		while (posA < A.length && posB < B.length) {
			int cmp = A[posA].compareTo(B[posB]);
			ans++;
			if (cmp < 0) {
				posA = advance(A, posA);
			} else if (cmp > 0) {
				posB = advance(B, posB);
			} else {
				posA = advance(A, posA);
				posB = advance(B, posB);
			}
		}
		while (posA < A.length) {
			ans++;
			posA = advance(A, posA);
		}
		while (posB < B.length) {
			ans++;
			posB = advance(B, posB);
		}
		return ans;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		for (int t = 0; t < T; ++t) {
			int N = sc.nextInt();
			int M = sc.nextInt();
			String[] cornell = new String[N];
			for (int i = 0; i < N; ++i)
				cornell[i] = sc.next();
			String[] white = new String[M];
			for (int i = 0; i < M; ++i)
				white[i] = sc.next();
			System.out.println(sizeInter(cornell, white));
		}
	}
}
