//  AUTHOR : fireLUFFY
//   NIT - ROURKELA
/*************************************/
#include<bits/stdc++.h>

#define ll  long long
#define ull unsigned long long     
#define vi vector<int>
#define vll vector<long long>
#define vvl vector<vector<long long>>
#define deql deque<long long>		//dequeue of type long long 
#define prquel priority_queue<long long>		//priority_queue of type long long 
#define loop(i,n) for(long long i=0;i<n;i++)
#define loopn(i,a,b) for(long long i=a;i<=b;i++)
#define rloop(i,n) for(long long i=n;i>0;i--)
#define sortv(a) sort(a.begin(),a.end())
#define sortvr(a) sort(a.rbegin(),a.rend())
#define verase(a) a.erase(unique(a.begin(),a.end()),a.end())	//erasing all duplicates in a vector 
#define pb push_back
#define pf push_front
#define fi first
#define se second 
using namespace std;

const ll MOD=1000000007;
unsigned long long fact(int a){long long f=1;for(long long i=1;i<=a;i++)f=(f*i);return f;} //till 20!
void copy(int a[],int b[],long long n) {for(long long i=0;i<n;i++) b[i]=a[i];}
void FASTIO(){ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);}

/****************************************************************************************/

void solve(ll t)
{
	ll testcases=t;
	while(t--)
	{
	//	cout<<"Test-Case #"<<(testcases-t)<<"\n";
		int n,m,c=0,x;
		cin>>n>>m;
		int a[101]={0};
		loop(i,n)
		{
			cin>>x;
			a[x]++;
		}
		loop(i,m)
		{
			cin>>x;
			a[x]++;
		}
		loop(i,101)
		{
			if(a[i]>1)
				c++;
		}
		cout<<c<<"\n";
	}
}

int main()
{
	time_t start,end;
	time(&start);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	FASTIO();	
	ll t;
	cin>>t;
	solve(t);
	time(&end);
	double time_taken=(double)(end-start);
//	cout<<"Time taken is : "<<fixed<<time_taken<<setprecision(5)<<" sec\n";
	return 0;
}