#include "bits/stdc++.h"
#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define pb push_back

using namespace std;
typedef pair<int, int> pii;

int main() {
    fastIO;
    int t;
    cin >> t;

    while (t--) {
        int n, m;
        cin >> n >> m;

        bool vis[101];
        memset(vis, false, sizeof(vis));
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            int temp;
            cin >> temp;
            vis[temp] = true;
        }

        for (int i = 0; i < m; i++) {
            int temp;
            cin >> temp;
            if (vis[temp]) cnt++;
        }

        cout << cnt << "\n";
    }
}
