//#define debug
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;

#define mset(a, b) memset(a, b, sizeof(a))
#define fill(a, b, c) fill(a, b+10, c)
#define mp make_pair
#define x first
#define y second

typedef long long LL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;

const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const LL LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const double PI = 3.14159265358979;

const int N = 1e6+10;
const int M = 1e6+10;

int n, m;
int a[N];

void solve() {
	cin >> n >> m; 
	for(int i = 1; i <= 100; i++) a[i] = 0;
	int x;
	for(int i = 0; i < n; i++) {
		cin >> x;
		a[x]++;
	}
	for(int i = 0; i < m; i++) {
		cin >> x;
		a[x]++;
	}
	int ans = 0;
	for(int i = 1; i <= 100; i++) {
		if(a[i]) ans++;
	}
	printf("%d\n", n+m-ans);
}

int main() {
	#ifdef debug
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	//*
	int T;
	cin >> T;
	while(T--) /**/ 
	{
		solve();
	}
	
	return 0;
}
