#define _CRT_SECURE_NO_WARNINGS
#define forn(i,n) for (LL i=0;i<n;i++)
#define foran(i,a,n) for (LL i=a;i<n;i++)
#define LL long long
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <bitset>
#include <map>
using namespace std;   //[65-90]

void ifdef()
{
#ifdef _DEBUG
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#else
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ifdef();

    LL t;
    cin >> t;
    while(t--)
    {
        LL n, m;
        cin >> n >> m;
        vector<LL> a(n);
        vector<LL> b(m);

        forn(i, n) cin >> a[i];
        forn(i, m) cin >> b[i];

        LL sz = 100;
        vector<bool> taba(sz, false);
        vector<bool> tabb(sz, false);
        forn(i, n) taba[a[i]-1] = true;
        forn(i, m) tabb[b[i]-1] = true;

        LL ans = 0;
        forn(i, sz)
        {
            if (taba[i] == tabb[i] && taba[i] == 1) ans++;
        }
        cout << ans << "\n";
        

       
        



    }
    
    
    


    return 0;
}