#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const ll mod = 1000000007;
const double PI = 3.14159265358979323846;
using namespace std;


int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif
  ll t;
  cin>>t;
  // t = 1;
  while(t--)
  {
  	ll n,m;
  	cin>>n>>m;
  	ll a[n];
  	ll b[m];
  	ll count[101]{0};
  	for(ll i = 0;i<n;i++)
  	{
  		cin>>a[i];
  		count[a[i]]++;
  	}
  	for(ll i = 0;i<m;i++)
  	{
  		cin>>b[i];
  		count[b[i]]++;
  	}
  	ll ans = 0;
  	for(ll i = 0;i<101;i++)
  	{
  		if(count[i]>1)
  			ans++;
  	}
  	cout<<ans<<"\n";
  }

}