#include<iostream>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int t,n;
char str1[N],str2[N],ts1[N],ts2[N];
void solve1(){
	int cnt=0;
	for(int i=1;i<=n;i++){
		cnt+=(str2[i]==str1[i]);	
	}
	cout<<cnt<<endl;
}
void solve2(){
	ll ans=0;
	int l=1,r=1;
	ll cnt1=0,cnt2=0,cnt3=0,cnt4=0;
	for(;r<=n+1;r++){
		if(ts1[r]=='0'||r==n+1){
			ans+=(min(cnt1,cnt3)+min(cnt2,cnt4))+(str1[r]==str2[r]); 
			cnt1=cnt2=cnt3=cnt4=0;
			//l=r+1;
			continue;
		}
		if(str1[r]=='0')cnt1++;
		if(str1[r]=='1')cnt2++;
		if(str2[r]=='0')cnt3++;
		if(str2[r]=='1')cnt4++;
	}
	cout<<ans<<endl;
}
bool cmp(char *a,char *b){
	for(int i=1;i<=n;i++){
		if(a[i]!=b[i])return false;
	}
	return true;
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>t;
	while(t--){
		cin>>n;
		cin>>(str1+1)>>(str2+1)>>(ts1+1)>>(ts2+1);
		if(cmp(ts1,ts2)){
			//cout<<t<<endl;
			str1[n+1]='0';
			str2[n+1]='1';
			solve2();
			continue;
		}
		solve1();
	}
//cin>>n;
//cin>>(ts1+1)>>(ts2+1);
//cout<<cmp(ts1,ts2);
	return 0;
}
/*
1
10
1001100101
1110011001
1111011111
1111011111
*/
