#include <bits/stdc++.h>
#define MAXN
using ll = long long;
using namespace std;
//I swear to go what ever will be.
int n;
string s1,s2,t1,t2;
int cnt1[2],cnt2[2];
struct node{
	int l,r;
};
void solve(){
	cin>>n;
	cin>>s1>>s2>>t1>>t2;
	cnt1[0]=cnt1[1]=0;
	cnt2[0]=cnt2[1]=0;
	s1=" "+s1;s2=" "+s2;t1=" "+t1;t2=" "+t2;
	int ans = 0;
	int pos1=1,pos2=1;
	node w1={0,0},w2={0,0};
	/*
	auto pntc = [&](){
		cerr<<"Cur cnt: cnt1_0="<<cnt1[0]<<" cnt1_1="<<cnt1[1]<<"\n";
		cerr<<"Cur cnt: cnt2_0="<<cnt2[0]<<" cnt2_1="<<cnt2[1]<<"\n";	
	};*/
	while(pos1<=n || pos2<=n){
		if(pos1==pos2){
			cnt1[0]=cnt1[1]=0;
			cnt2[0]=cnt2[1]=0;
		}
		if(pos1<pos2){//develop s1
			cnt1[0]=cnt1[1]=0;
			int R = pos1;
			while(R<=n && t1[R]=='1'){
				cnt1[s1[R]-'0']++;
				R++;
			} 
			if(R==pos1){
				cnt1[s1[R]-'0']++;
				R++;
			}
			w1 = {pos1,R-1};
			//pntc();
			//match
			int crs = min(w1.r,w2.r)-max(w1.l,w2.l)+1;
			if(crs>0){
				int mtc0 = min(cnt1[0],cnt2[0]);
				mtc0=min(mtc0,crs);
				cnt1[0]-=mtc0; cnt2[0]-=mtc0;
				ans += mtc0;
				crs -= mtc0;
				 
				int mtc1 = min(cnt1[1],cnt2[1]);
				mtc1=min(mtc1,crs);
				cnt1[1]-=mtc1; cnt2[1]-=mtc1;
				ans += mtc1;
				crs -= mtc1;
				//cerr<<"on "<<pos1<<" "<<pos2<<" got "<<mtc0+mtc1<<"\n";
			}
			
			
			//update pos
			pos1=R;
			
			//cerr<<"TYPE 1\n";
		}else{//develop s2
			cnt2[0]=cnt2[1]=0;
			int R = pos2;
			while(R<=n && t2[R]=='1'){
				cnt2[s2[R]-'0']++;
				R++;
			} 
			if(R==pos2){
				cnt2[s2[R]-'0']++;
				R++;
			}
			//pntc();
			//match
			w2 = {pos2,R-1};
			int crs = min(w1.r,w2.r)-max(w1.l,w2.l)+1;
			if(crs>0){
				int mtc0 = min(cnt1[0],cnt2[0]);
				mtc0=min(mtc0,crs);
				cnt1[0]-=mtc0; cnt2[0]-=mtc0;
				ans += mtc0;
				crs -= mtc0;
				 
				int mtc1 = min(cnt1[1],cnt2[1]);
				mtc1=min(mtc1,crs);
				cnt1[1]-=mtc1; cnt2[1]-=mtc1;
				ans += mtc1;
				crs -= mtc1;
				//cerr<<"on "<<pos1<<" "<<pos2<<" got "<<mtc0+mtc1<<"\n";
			}
			pos2=R;
			
			//cerr<<"TYPE 2\n";
		}
	} 
	cout<<ans<<"\n";
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin.tie(nullptr)->sync_with_stdio(false);
	int T;cin>>T;while(T--)solve(); 
	return 0;
} 
