#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int n;
string s1,s2,t1,t2;
struct are{
	int l,r,num0,num1;
};
deque<are>q[3];
void solve(){
	while(!q[1].empty())q[1].pop_front();
	while(!q[2].empty())q[2].pop_front();
	cin>>n>>s1>>s2>>t1>>t2;
	int nm0=0,nm1=0,sta=0,ans=0;
	for(int i=0;i<n;i++){
		if(t1[i]=='0'){
			if(sta==i)q[1].push_back({i,i,(s1[i]=='0'?1:0),(s1[i]=='1'?1:0)});
			else{
				q[1].push_back({sta,i-1,nm0,nm1});
				q[1].push_back({i,i,(s1[i]=='0'?1:0),(s1[i]=='1'?1:0)});
			}
			sta=i+1;
			nm0=nm1=0;
		}
		else{
			if(s1[i]=='0')nm0++;
			else nm1++;
		}
	}
	if(t1[n-1]=='1')q[1].push_back({sta,n-1,nm0,nm1});
	nm0=nm1=sta=0;
	for(int i=0;i<n;i++){
		if(t2[i]=='0'){
			if(sta==i)q[2].push_back({i,i,(s2[i]=='0'?1:0),(s2[i]=='1'?1:0)});
			else{
				q[2].push_back({sta,i-1,nm0,nm1});
				q[2].push_back({i,i,(s2[i]=='0'?1:0),(s2[i]=='1'?1:0)});
			}
			sta=i+1;
			nm0=nm1=0;
		}
		else{
			if(s2[i]=='0')nm0++;
			else nm1++;
		}
	}
	if(t2[n-1]=='1')q[2].push_back({sta,n-1,nm0,nm1});
//	while(!q[1].empty()){
//		are tmp=q[1].front();
//		q[1].pop_front();
//		cout<<tmp.l<<" "<<tmp.r<<" "<<tmp.num0<<" "<<tmp.num1<<"\n";
//	}
//	while(!q[2].empty()){
//		are tmp=q[2].front();
//		q[2].pop_front();
//		cout<<tmp.l<<" "<<tmp.r<<" "<<tmp.num0<<" "<<tmp.num1<<"\n";
//	}
	while(!q[1].empty()&&!q[2].empty()){
		are tmp1=q[1].front(),tmp2=q[2].front();
		q[1].pop_front();
		q[2].pop_front();
		if(tmp1.r<tmp2.r){
			if(tmp1.r<tmp2.l){
				q[2].push_front(tmp2);
				continue;
			}
			int min1=min(min(tmp1.num0,tmp2.num0),tmp1.r-max(tmp1.l,tmp2.l)+1),min2=min(min(tmp1.num1,tmp2.num1),tmp1.r-max(tmp1.l,tmp2.l)+1);
			ans=ans+min1+min2;
//			tmp1.num0-=min1;
			tmp2.num0-=min1;
//			tmp1.num1-=min2;
			tmp2.num1-=min2;
			q[2].push_front(tmp2);
		}
		else{
			if(tmp2.r<tmp1.l){
				q[1].push_front(tmp1);
				continue;
			}
			int min1=min(min(tmp1.num0,tmp2.num0),tmp2.r-max(tmp1.l,tmp2.l)+1),min2=min(min(tmp1.num1,tmp2.num1),tmp2.r-max(tmp1.l,tmp2.l)+1);
			ans=ans+min1+min2;
			tmp1.num0-=min1;
//			tmp2.num0-=min1;
			tmp1.num1-=min2;
//			tmp2.num1-=min2;
			q[1].push_front(tmp1);
		}
	}
	cout<<ans<<"\n";
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	int t;
	cin>>t;
	while(t--)solve();
	return 0;
}

