#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll ,ll>
using namespace std ;
const ll z = 998244353 ;
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("inputf.txt" , "r" , stdin) ;
freopen("outputf.txt" , "w" , stdout) ;
freopen("error.txt" , "w" , stderr) ;
#endif
int t ;
cin >> t ;
while(t--)
{
int n ;
cin >> n ;
vector<int> a(n) , b(n) ;
for(int i = 0 ; i < n ; i++)
{
cin >> a[i] ;
}
for(int i = 0 ; i < n ; i++)
{
cin >> b[i] ;
}
int ans = 0 ;
for(int i = 0 ; i < n ; i++)
if(a[i] == b[i])
ans++ ;
cout << ans << endl ;
}
return 0;
}