#include #include #include #include using namespace std; const int MAXN = 100000 + 10; const int MAX_AI = 1000000; int a[MAX_AI]; int main(int argc, const char * argv[]) { int tn; scanf("%d", &tn); assert(1 <= tn && tn <= 5); while (tn--) { int n, m; scanf("%d %d", &n, &m); assert(1 <= n && n <= 100000); assert(1 <= m && m <= 100000); for(int i = 1; i <= MAX_AI; i++) { a[i] = 0; } int ret = 0; for(int i = 0; i < n; i++) { int x; scanf("%d", &x); assert(1 <= x && x <= 1000000); assert((a[x] & 1) == 0); a[x] |= 1; } for(int i = 0; i < m; i++) { int x; scanf("%d", &x); assert(1 <= x && x <= 1000000); assert((a[x] & 2) == 0); a[x] |= 2; if (a[x] == 3) { ++ret; } } printf("%d\n", ret); } return 0; }