#include <iostream>
#include <algorithm>
#include <cstring>
using namespace  std;

int vis[200];
int main (void){
    
    int T;
    cin >> T;
    while (T -- ){
        int n, m;
        cin >> n >> m;
        memset(vis, 0, sizeof vis);
        int x, ans = 0;
        for (int i = 0; i < n; i ++ ) cin >> x, vis[x] = 1;
        for (int i = 0; i < m; i ++ ) {
            cin >> x;
            if (vis[x]) ans ++;
        }
        cout << ans << endl;
    }
    return 0;
}

  	 	    	    	 		 		 	 		    	