// 2^j = <<
// >> ->divide by 2

#include<bits/stdc++.h>
using namespace std;


#define debug(val) printf("check%d\n",val)
#define int long long
#define mod 1000000007
#define clr(val) memset(val,0,sizeof(val))
#define watch(x) cerr << #x << " is " << x << endl;
//vec.erase( unique( vec.begin(), vec.end() ), vec.end() );
#define endl '\n'
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int inf = 1e9 + 5;



int32_t main() {
  FIO;  
  
  int t;
  for(cin>>t;t--;){
    
    int m,n;
    cin>>n>>m;
    int sum=m+n;
    set<int> s;
    while(n--){
      int a;
      cin>>a;
      s.insert(a);
    }
    while(m--){
      int b;
      cin>>b;
      s.insert(b);
    }
    cout<<sum-s.size()<<endl;


    
  }//end of TC

  return 0;


}



