#include<bits/stdc++.h>
#define ll long long 
#define R register
using namespace std;
const int N=1e5+5;
struct node{int st;bool which;};
vector<node> v;
string s,t,ss,tt;bool tus[N],tut[N];int n,sums[N][2],sumt[N][2];
namespace SUB0{
	inline bool chk(){
		return (n<=10);
	}
	inline bool check(int state,string ss,bool op){
		string s1;s1=" "+s1;
		for(R int i=0;i<n;++i){
			s1+=char(((state>>i)&1)+'0');
		}
		int cnt0=0,cnt1=0,cntt0=0,cntt1=0;
		for(R int i=1;i<=n;++i){
			if(!op){
				if(!tus[i]){
					if(ss[i]!=s1[i])return 0;
					if(cnt0!=cntt0||cnt1!=cntt1)return 0;
					cnt0=cntt0=cnt1=cntt1=0;
				}else{
					if(ss[i]=='1')++cnt1;
					else ++cnt0;
					if(s1[i]=='1')++cntt1;
					else ++cntt0; 
				}
			}else{
				if(!tut[i]){
					if(ss[i]!=s1[i])return 0;
					if(cnt0!=cntt0||cnt1!=cntt1)return 0;
					cnt0=cntt0=cnt1=cntt1=0;
				}else{
					if(ss[i]=='1')++cnt1;
					else ++cnt0;
					if(s1[i]=='1')++cntt1;
					else ++cntt0; 
				}
			}
		}
		if(cnt1==cntt1&&cnt0==cntt0)return 1;
		return 0;
	}
	inline void solve(){
		int all=(1<<n)-1;
		int mx=0;
		for(R int i=0;i<=all;++i){
			if(check(i,s,0)){
				for(R int j=0;j<=all;++j){
					if(check(j,t,1)){
						int siz=n;
						int cntt=__builtin_popcount((i^j));
						mx=max(mx,siz-cntt);
					}
				}	
			}
		}
		cout<<mx<<'\n';
	}
}
namespace SUB1{
	inline bool chk(){
		for(R int i=1;i<n;++i){
			if(s[i+1]!=s[i])return 0;
		}
		return 1;
	}
	inline void solve(){
		if(s[1]=='1'){
			int res=0;
			for(R int i=1;i<=n;++i)res+=(t[i]=='1');
			cout<<res<<'\n';
		}else{
			int res=0;
			for(R int i=1;i<=n;++i)res+=(t[i]=='0');
			cout<<res<<'\n';
		}
	}
}
namespace SUB2{
	inline bool chk(){return ss==tt;}
	inline void solve(){
		int s0=0,s1=0,t0=0,t1=0,res=0;
		for(R int i=1;i<=n;++i){
			if(!tus[i]){
				res+=min(s0,t0)+min(s1,t1)+(s[i]==t[i]);
				s0=t0=s1=t1=0;
			}else{
				if(s[i]=='0')++s0;
				else ++s1;
				if(t[i]=='0')++t0;
				else ++t1;
			}
		}
		cout<<res+min(s0,t0)+min(s1,t1)<<'\n';
	}
}
namespace SUB3{
	inline bool chk(){
		int cnt1=0,cnt2=0;
		for(R int i=1;i<=n;++i)cnt1+=(!tus[i]);
		for(R int i=1;i<=n;++i)cnt2+=(!tut[i]);
		return (cnt1==1&&cnt2==1);
	}
	inline void solve(){
		int poss=0,post=0;
		for(R int i=1;i<=n;++i){
			if(!tus[i])poss=i;
			if(!tut[i])post=i;
		}
		int res=0;
		if(poss<post){
			int s0=sums[poss][0],s1=sums[poss][1],t0=sumt[post-1][0],t1=sumt[post-1][1];
			int add0=min(s0,t0),add1=min(s1,t1);
			res+=add0+add1;
			s0-=add0,t0-=add0,s1-=add1,t1-=add1;
			if(s0)t1-=s0,s0=0;
			if(s1)t0-=s1,s1=0;
			if(t[post]=='1')++t1;
			else ++t0;
			s0=sums[n][0]-sums[poss][0];s1=sums[n][1]-sums[poss][1];
			t1+=sumt[n][1]-sumt[post][1];t0+=sumt[n][0]-sumt[post][0];
			res+=min(s0,t0)+min(s1,t1);
			cout<<res<<'\n';
		}else{
			int t0=sums[post][0],t1=sumt[post][1],s0=sums[poss-1][0],s1=sums[poss-1][1];
			int add0=min(s0,t0),add1=min(s1,t1);
			res+=add0+add1;
			s0-=add0,t0-=add0,s1-=add1,t1-=add1;
			if(t0)s1-=t0,t0=0;
			if(t1)s0-=t1,t1=0;
			if(s[poss]=='1')++s1;
			else ++s0;
			t0=sumt[n][0]-sumt[post][0];t1=sumt[n][1]-sumt[post][1];
			s1+=sums[n][1]-sums[poss][1];s0+=sums[n][0]-sums[poss][0];
			res+=min(s0,t0)+min(s1,t1);
			cout<<res<<'\n';
		}
	}
}
inline void del(int a,int b,int c,int d,int op){
	int add0=min(a,c),add1=min(b,d);
	if(op){
		if(a)d-=a,a=0;
		if(b)c-=b,b=0;
	}else{
		if(c)b-=c,c=0;
		if(d)a-=d,d=0;
	}
}
inline void solve(){
	cin>>n>>s>>t>>ss>>tt;s=" "+s,t=" "+t;ss=" "+ss,tt=" "+tt;
	int res=0;
	for(R int i=1;i<=n;++i){
		tus[i]=ss[i]-'0';
	}
	for(R int i=1;i<=n;++i){
		tut[i]=tt[i]-'0';
	}
	for(R int i=1;i<=n;++i){
		sums[i][0]=sums[i-1][0],sums[i][1]=sums[i-1][1];
		++sums[i][s[i]-'0'];
	}
	for(R int i=1;i<=n;++i){
		sumt[i][0]=sumt[i-1][0],sumt[i][1]=sumt[i-1][1];
		++sumt[i][t[i]-'0'];
	}
	if(SUB0::chk())return SUB0::solve();
	if(SUB1::chk())return SUB1::solve();
	if(SUB2::chk())return SUB2::solve();
	if(SUB3::chk())return SUB3::solve();
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int _;cin>>_;while(_--)solve();
	return 0;
}
