#include<bits/stdc++.h>
using namespace std;

const int N=100005;
int s1[N],s2[N];
int n,T;
bool vis1[N],vis2[N];
int pre1[N],pre2[N];
int cnt1_1[N],cnt1_0[N],cnt2_1[N],cnt2_0[N]; 

int getc(){
	char c=getchar();
	while(c!='0'&&c!='1'){
		c=getchar();
	}
	return c-'0';
}

void init(){
	memset(s1,0,sizeof(s1));
	memset(s2,0,sizeof(s2));
	memset(pre1,0,sizeof(pre1));
	memset(pre2,0,sizeof(pre2));
	memset(cnt1_1,0,sizeof(cnt1_1));
	memset(cnt1_0,0,sizeof(cnt1_0));
	memset(cnt2_1,0,sizeof(cnt2_1));
	memset(cnt2_0,0,sizeof(cnt2_0));
	memset(vis1,0,sizeof(vis1));
	memset(vis2,0,sizeof(vis2));
}

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout); 
	
	cin>>T;
	while(T--){
		init();
		cin>>n;
		for(int i=1;i<=n;i++){
			s1[i]=getc();
			if(s1[i]==0){
				cnt1_0[i]=cnt1_0[i-1]+1;
				cnt1_1[i]=cnt1_1[i-1];
			}
			else{
				cnt1_0[i]=cnt1_0[i-1];
				cnt1_1[i]=cnt1_1[i-1]+1;
			}
		}
		
		for(int i=1;i<=n;i++){
			s2[i]=getc();
			if(s2[i]==0){
				cnt2_0[i]=cnt2_0[i-1]+1;
				cnt2_1[i]=cnt2_1[i-1];
			}
			else{
				cnt2_0[i]=cnt2_0[i-1];
				cnt2_1[i]=cnt2_1[i-1]+1;
			}
		}
//		if(cnt1_1[n]==n){
//			cout<<cnt2_1[n]<<endl;
//			continue;
//		}
//		if(cnt1_0[n]==n){
//			cout<<cnt2_0[n]<<endl;
//			continue; 
//		} 
//		cout<<s1<<endl<<s2;
		for(int k=0,i=1;i<=n;i++){
			vis1[i]=getc();
			if(!vis1[i]){
				k=i;
			}
			pre1[i]=k;
		}
		
		for(int k=0,i=1;i<=n;i++){
			vis2[i]=getc();
			if(!vis2[i]){
				k=i;
			}
			pre2[i]=k;
		}
		
		int r=n;
		int ans=0;
		while(r>=1){
			int l=max(pre1[r],pre2[r]);
			ans+=min(cnt1_1[r]-cnt1_1[l-1],cnt2_1[r]-cnt2_1[l-1])+min(cnt1_0[r]-cnt1_0[l-1],cnt2_0[r]-cnt2_0[l-1]);
//			if((s1[l]!=s2[l])&&(!vis1[l]&&!vis2[l])) ans--; 
			r=l-1;
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
} 
