#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
int n;
char a[maxn],b[maxn],cana[maxn],canb[maxn];
bool check_A(){
	for(int i=2;i<=n;i++){
		if(a[i]!=a[1]){
			return false;
		}
	}return true;
}void solve_A(){
	int cnt=0;
	for(int i=1;i<=n;i++){
		cnt+=b[i]-'0';
	}printf("%d\n",a[1]-'0'?cnt:n-cnt);
}void solve(){
	scanf("%d",&n);
	scanf("%s",a+1);
	scanf("%s",b+1);
	scanf("%s",cana+1);
	scanf("%s",canb+1);
	if(check_A()){
		solve_A();
	}
}signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	scanf("%d",&t);
	while(t--){
		solve();
	}
	return 0;
}
