#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int T;
int n;
char s1[10005],s2[10005];
bool t1[10005],t2[10005];
bool checkA(string a){
	int ans1=0,ans2=0;
	for(int i = 1;i <= n;i++){
		if(a[i] == '1') ans1++;
		if(a[i] == '0') ans2++;
		if(ans1 == n || ans2 == n) return true;
		else return false;
	}
}
bool checkC(bool a[],bool b[]){
	int numa=0,numb=0;
	for(int i = 1;i <= n;i++){
		numa += a[i];
		numb += b[i];
	}
	if(numa == n-1 && numb == n-1) return true;
	else return false;
}
int compareA(string a,string b){
	int ans = 0;
	for(int i = 1;i <= n;i++){
		if(a[i] == b[i]) ans++;
	}
	return ans;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> T;
	while(T--){
		cin >> n;
		cin >> s1 >> s2;
		for(int i = 1;i <= n;i++){
			cin >> t1[i];
		}
		for(int i = 1;i <= n;i++){
			cin >> t2[i];
		}
		if(checkA(s1)){
			int ans = compareA(s1,s2);
			cout << ans << endl;
		}
		if(checkC(t1,t2)){
			
		}
	}
} 
