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

int main() {
    cout.tie(nullptr)->sync_with_stdio(false);
    int T; cin >> T;

    while (T--) {
        int N, M; cin >> N >> M;
        vector<int> A(110);
        for (int i = 0; i < N; ++i) {
            int a; cin >> a;
            A[a]++;
        }
        int res = 0;
        for (int i = 0; i < M; ++i) {
            int b; cin >> b;
            if (A[b] > 0) ++res;
        }
        cout << res << '\n';
    }
}
