// CODED BY ABDALAH ABUSALAH
// ~/SolverToBe/Developers/KnightK0der
/*
#---================================================================---#
#                                                                      #
# .d888888   dP                .d88888b           dP          dP       #
# d8     88  88                88.                88          88       #
# 88aaaaa88  88d888b. dP    dP `Y88888b. .d8888b. 88 .d8888b. 88d888b. #
# 88     88  88'  `88 88    88       `8b 88'  `88 88 88'  `88 88'  `88 #
# 88     88  88.  .88 88.  .88 d8'   .8P 88.  .88 88 88.  .88 88    88 #
# 88     88  88Y8888' `88888P'  Y88888P  `88888P8 dP `88888P8 dP    dP #
#                                                                      #
# .....................................................................#
# .......={====== ./ Contact With Me @ FB.COM/MRABUSALAH ======}=......#
# ....................*/#include <bits/stdc++.h>/*.....................#
#---================================================================---#
*/

using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define f(n, x) for (int x = 0; x < (int)(n); ++x)
#define all(a) a.begin(),a.end()
#define endl '\n'
#define scantc scanf("%d",&tc);
#define scann scanf("%d",&n);
#define scana scanf("%d",&a);
#define in(x) scanf("%d",&x);
#define inl(x) scanf("%lld",&x);
#define l(s) s.length();
#define S second
#define F first
#define pb push_back
#define NumofDigits(n) ((int)log10(n)+1)
typedef vector<int> vi;
typedef vector<pair<int, int>> vip;
const int N = 100000 + 10;
const double PI = 3.14159;

int gcd(int a, int b) {
    return !b ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}

int randomNum() {
    return rand() % 100 + 1;
}

double distanceBetweenTwoPoints(double x, double y, double a, double b) {
    return sqrt(pow(x - a, 2) + pow(y - b, 2));
}

bool isPrime(ll n) {
    if (n == 2) {
        return true;
    }
    if ((n < 2) || !(n % 2)) {
        return false;
    }
    for (int i = 3; i * i <= n; i += 2) {
        if (!(n % i))
            return false;
    }
    return true;
}

bool twoPointers(vector<int> v, int key) {
    int left = 0, right = v.size() - 1;
    while (left < right) {
        if (v[left] + v[right] == key)
            return 1;
        else if (v[left] + v[right] > key)
            right--;
        else
            left++;
    }
    return 0;
}

void calcTime() {
    clock_t t;
    t = clock();
    //myCode();
    t = clock() - t;
    double time_taken = ((double) t) / CLOCKS_PER_SEC; // calculate the elapsed time
    printf("The program took %f seconds to execute", time_taken);

}

int dr[4] = {0, 1, 0, -1};
int dc[4] = {1, 0, -1, 0};
// x |= (1<<i) to make a bit = 1
// x &= ~(1<<i) to clear a bit = 0
// x & (1<<j) to check if bit j is 1 in x


/*
[#]=============================================================[#]
         ___    ____              ____          ___ _
        |_ _|  / ___|__ _ _ __   |  _ \  ___   |_ _| |_
         | |  | |   / _` | '_ \  | | | |/ _ \   | || __|
         | |  | |__| (_| | | | | | |_| | (_) |  | || |_
        |___|  \____\__,_|_| |_| |____/ \___/  |___|\__|
                     it's just about time

[#]=============================================================[#]
*/

inline void start() {
    // return (sudo apt-get ACCEPTED)
}


int tc, n, m, a;

inline void solve() {

    cin >> tc;
    while (tc--) {
        int ans = 0;
        map<int, int> mp;
        cin >> n >> m;
        for (int i = 0; i < n; ++i) {
            scana
            mp[a]++;
        }
        for (int j = 0; j < m; ++j) {
            scana
            mp[a]++;
        }
        for (auto it = mp.begin(); it != mp.end(); it++) {
            if (it->second > 1) {
                ans++;
            }
        }
        cout << ans << endl;
    }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
#endif
    //========================//
    /*||*/                /*||*/
    /*||*/    start();    /*||*/
    /*||*/    solve();    /*||*/
    /*||*/                /*||*/
    //========================//

    return 0;
}