#include <bits/stdc++.h>

using namespace std;
const int maxn = 105 + 7;

int num[maxn];
int main() {
    int T;scanf("%d",&T);
    while(T--) {
        int n,m,res = 0;scanf("%d %d",&n,&m);
        memset(num,0,sizeof(num));
        for(int i = 1,x;i <= n;++i) {
            scanf("%d",&x); num[x]++;
        }for(int i = 1,x;i <= m;++i) {
            scanf("%d",&x);if(num[x]) res++;
        }printf("%d\n", res);
    }    
    return 0;
}