#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;

string s1,s2,s3,s4;
bool cnt[2][N];
int n,len,len2,ans;
queue<pair<int,int> > q,q2;
queue<pair<int,int> > c1,c2;
queue<int> f;
bool d[N];
bool d2[N];

void func(){
	for(int i=0;i<n;i++){
		if(s3[i]=='0'){
			if(s1[i]==s2[i]){
				ans++;
			}
		}
	}
//	cout<<ans<<endl;
	while(!q.empty()){
			int x1=0,y1=0,x2=0,y2=0;
			pair<int,int> c=q.front();
			for(int i=c.first;i<=c.second;i++){
				if(s1[i]=='1')x1++;
				else y1++;
				if(s2[i]=='1')x2++;
				else y2++;
			}
//			cout<<x1<<" "<<y1<<" "<<x2<<" "<<y2<<endl;
			ans+=min(x1,x2)+min(y1,y2);
			q.pop();
		}cout<<ans<<endl;
}

void func2(){
	for(int i=0;i<n;i++){
		if(s1[i]==s2[i])ans++;
	}cout<<ans<<endl;
}

void func3(){
	int c1x,c2x;
	for(int i=0;i<n;i++){
		if(s1[i]=='0')c1x=i;
		if(s2[i]=='0')c2x=i;
	}
	bool pd=1;
	for(int i=c1x;i<=c2x;i++){
		if((s3[i]==0&&s4[i]==0)){
			pd=0;
			break;
		}
	}
	if(pd){
		cout<<n<<endl;
	}
	else{
		cout<<n-2<<endl;
	}
}

int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin>>t;
	while(t--){
		ans=0,len=0;len2=0;
		while(!f.empty())f.pop();
		while(!q.empty())q.pop();
		while(!q2.empty())q2.pop(); 
		while(!c1.empty())c1.pop();
		while(!c2.empty())c2.pop();
		cin>>n;
		cin>>s1>>s2;
		cin>>s3>>s4;
		
		int lst=-1,tmp;
		for(int i=0;i<n;i++){
			tmp=s3[i]-'0';
			cnt[0][i]=tmp;
			if(tmp==1){
				if(lst==-1){
					lst=i;
				}
			}
			else{
				if(lst!=-1){
					 q.push({lst,i-1});
					c1.push({lst,i-1});
					lst=-1;
				}
			}
		}
		if(lst!=-1){
			 q.push({lst,n-1});
			c1.push({lst,n-1});
			lst=-1;
		}

		for(int i=0;i<n;i++){
			tmp=s4[i]-'0';
			cnt[1][i]=tmp;
			if(tmp){
				if(lst==-1){
					lst=i;
				}
			}
			else{
				if(lst!=-1){
					q2.push({lst,i-1});
					c2.push({lst,i-1});
					lst=-1;
				}
			}
		}
		if(lst!=-1){
			q2.push({lst,n-1});
			c2.push({lst,n-1});
			lst=-1;
		}
		if(s3==s4){
			func();
			continue;
		}
		bool pd=1;
		for(int i=0;i<n;i++){
			if(s1[i]!=s2[i]){
				pd=0;
				break;
			}
		} 
		if(pd){
			func2();
			continue;
		}
		int cunt1=0,cunt2=0;
		for(int i=0;i<n;i++){
			if(s1[i]=='0')cunt1++;
			if(s2[i]=='0')cunt2++;
		} 
		if(cunt1==1&&cunt2==1){
			func3();
			continue; 
		}
//		while(!q.empty()){
//			pair<int,int> x=q.front();q.pop();
//			cout<<x.first<<" "<<x.second<<endl;
//		}
		pair<int,int> x=q.front();//x=q2
		pair<int,int> y=q2.front(); //y=q
		while((!q2.empty())&&(!q.empty())){
//			cout<<"1/n";
			while((!q2.empty())&&(!q.empty())){
				if(x.first>=y.first&&x.second<=y.second){
//					cout<<"clean>"<<x.first<<"-"<<x.second<<endl;
					for(int i=x.first;i<=x.second;i++)cnt[0][i]=0;
					q.pop();
					if(!q.empty())x=q.front();
				}
				if(x.first<=y.first&&x.second>=y.second){
//					cout<<"clean<"<<y.first<<"-"<<y.second<<endl;
					for(int i=y.first;i<=y.second;i++)cnt[1][i]=0;
					q2.pop();
					if(!q2.empty())y=q2.front();
				}
				if(x.first<y.first&&x.second<=y.second){
					q.pop();
					if(!q.empty())x=q.front();
				}
				if(x.first>=y.first&&x.second>y.second){
					q2.pop();
					if(!q2.empty())y=q2.front();
				}
			}
		}
//		cout<<"end\n";
//		for(int i=0;i<n;i++){
//			if(cnt[0][i])cout<<1;
//			else cout<<0;
//		}cout<<endl;
//		for(int i=0;i<n;i++){
//			if(cnt[1][i])cout<<1;
//			else cout<<0;
//		}cout<<endl;
		
		while(!c1.empty()){
			int x1=c1.front().first;
			int onum=0,onum2=0;
//			cout<<"x>"<<x1<<endl;
			if(!cnt[0][x1]){
				c1.pop();
				continue;
			}
			int l=-1,r=-1;
			for(int i=x1;i<n&&cnt[0][i];i++){
				
				if(l==-1&&cnt[1][i]==0)l=i;
				if(cnt[1][i]==0){
					r=i;
					if(s1[i]=='1')onum2++;
					if(s2[i]=='1'&&l!=-1)onum++;
				}
			}
			
//			cout<<"ept>"<<l<<"-"<<r<<":"<<onum<<endl;
			
			ans+=(r-l+1)-abs(onum-onum2);
//			cout<<"r,l"<<r<<","<<l<<endl<<"n1"<<onum<<endl<<"n2"<<onum2<<endl;
//			cout<<"ans+"<<(r-l+1)-abs(onum-onum2)<<endl;
//			cout<<"push:"<<(abs(c1.front().first-l)+abs(c1.front().second-r))<<endl;
			f.push(abs(c1.front().first-l)+abs(c1.front().second-r));
			for(int i=c1.front().first;i<=c1.front().second;i++){
				if(onum2<1){
					d[len++]=0;
				}
				else{
					if(onum-1<0)d[len++]=1;
					else{
						d[len++]=0;
					} 
				}
			}
			
			c1.pop();
		}
//		cout<<"2\n";
		while(!c2.empty()){
			int x1=c2.front().first;
			int onum=0,onum2=0;
//			cout<<"x>"<<x1<<endl;
			if(!cnt[1][x1]){
				c2.pop();
				continue;
			}
			int l=-1,r=-1;
			for(int i=x1;i<n&&cnt[1][i];i++){
				
				if(l==-1&&cnt[0][i]==0)l=i;
				if(cnt[0][i]==0){
					r=i;
					if(s2[i]=='1')onum2++;
					if(s1[i]=='1'&&l!=-1)onum++;
				}
			}
//			cout<<"ept>"<<l<<"-"<<r<<":"<<onum<<endl;
//			cout<<"n1"<<onum<<endl<<"n2"<<onum2<<endl;
			ans+=(r-l+1)-abs(onum-onum2);
//			cout<<"ans+"<<(r-l+1)-abs(onum-onum2)<<endl;
			for(int i=c2.front().first;i<=c2.front().second;i++){
				if(onum2<1){
					d2[len2++]=0;
				}
				else{
					if(onum-1<0)d2[len2++]=1;
					else{
						d2[len2++]=0;
					} 
				}
			}
			
			c2.pop();
		}
//		cout<<"-------------------"<<"ans1="<<ans<<endl;
		while(!f.empty()){
			int l=f.front();f.pop();
//			cout<<"l="<<l<<endl;
			for(int i=0;i<l;i++){
				if(d[i]==d2[i])ans++;
			}
			
		}
		cout<<ans<<endl;
	}
	return 0;
}
//最后一次打信息竞赛，死于死磕第一题，看来只能走文化了，AFO 
//“还在争，还在争，争个不停的”....下次再也不争了（当然没有下次了） 
//Luogu:_None 
//有兴趣就交个朋友吧——致看公示代码的朋友 
