#include<bits/stdc++.h> 
using namespace std;
#define ll long long
const int N=1e5+10;
ll T,n,ans;
string s1,s2,s3,s4;
ll tj1[N],tj2[N],tj3[N],tj4[N],top3,top4;
bool fs1[N],fs2[N];
void chk(ll l,ll r,ll need)
{
	if(fs1[need]) return;
	if(s1[need]==s2[need]) 
	{
		ans++;
		fs1[need]=true;
		return;
	}
	if(s3[l]=='0'||s3[r]=='0') return;	
	if(l<0||r>=n) return;
	if(!fs1[l]&&s1[l]==s2[need])
	{
		swap(s1[l],s1[need]);
		ans++;
		fs1[need]=true;
		return;
	}
	if(!fs1[r]&&s1[r]==s2[need])
	{
		swap(s1[r],s1[need]);
		ans++;
		fs1[need]=true;
		return;
	}
	chk(l-1,r,need);
	chk(l,r+1,need);
}
int main()
{
	
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--)
	{
		cin>>n;
		cin>>s1>>s2>>s3>>s4;
		ll i=0,j=0,f3=0,f4=0;
		ans=0;
		bool f=true,f2=true;
		for(ll k=0;k<n;k++)
		{
			if(k+1<n&&s1[k]!=s1[k+1])
		  {
		  	f=false;
		  }
		    if(s3[k]!=s4[k])
		    {
		    	f2=false;
			}
			if(s1[i]=='0')
			{
				f3++;
			}
			if(s2[i]=='0')
			{
				f4++;
			}
		}
		  
		if(f==true)
		{
			char c=s1[0];
			for(;i<n;i++)
			  if(s2[i]==c) ans++;
			cout<<ans<<endl;
			continue;
		}
		else if(f2==true)
		{
			ll s=0,tj11=0,tj10=0,tj21=0,tj20=0;
			for(;i<n;i++)
			{
				if(s3[i]=='0')
				{
					ans+=min(tj11,tj21)+min(s-tj11,s-tj21);
					if(s1[i]==s2[i]) ans++; 
					tj11=0;
					tj21=0;
					s=0;
					continue;
				}
				s++;
				if(s1[i]=='1') tj11++;
				if(s2[i]=='1') tj21++;
			}
			if(s!=0) ans+=min(tj11,tj21)+min(s-tj11,s-tj21);
			cout<<ans<<endl;
			continue;
		}
		memset(fs1,false,sizeof(fs1));
		memset(tj2,0,sizeof(tj2));
		top3=top4=0;
		for(ll k=0;k<n;k++)
		{
			
			tj1[k]=(k!=0?tj1[k-1]:0)+s1[i]-'0';
			tj2[k]=(k!=0?tj2[k-1]:0)+s2[i]-'0';
			if(s3[k]=='0') tj1[k]=0,tj3[++top3]=k;
			if(s4[k]=='0') tj2[k]=0,tj4[++top4]=k;
		}
		for(ll i=0;i<n;i++)
		{
			chk(i,i,i);
		}
		swap(s1,s2);swap(s3,s4);
		for(ll i=0;i<n;i++)
		{
			chk(i,i,i);
		}
		cout<<ans<<endl;
	}
	return 0;
}
