#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define bll __int128
#define vii vector<int>
#define vll vector<ll>
#define pb push_back
#define ppb pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define sec second
#define mp make_pair
#define qii queue<int>
#define puu pair<ull,ull>
#define clr clear
using namespace std;
const int N=1e5+5;
string s1,s2,t1,t2;
int bel1[N],bel2[N];
int s10[N],s11[N],s20[N],s21[N];
int T,n,S1,S2;
void push1(int l,int r)
{
	if(l>r)return ;
	S1++;
	for(int i=l;i<=r;i++)bel1[i]=S1,s10[S1]+=(s1[i]=='0'),s11[S1]+=(s1[i]=='1');
}
void push2(int l,int r)
{
	if(l>r)return ;
	S2++;
	for(int i=l;i<=r;i++)bel2[i]=S2,s20[S2]+=(s2[i]=='0'),s21[S2]+=(s2[i]=='1');
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n>>s1>>s2>>t1>>t2,s1=' '+s1,s2=' '+s2,t1=' '+t1,t2=' '+t2,S1=0,S2=0;
		for(int i=1;i<=n;i++)s10[i]=s20[i]=s11[i]=s21[i]=bel1[i]=bel2[i]=0;
		int las=1,ans=0;
		for(int i=1;i<=n;i++)if(t1[i]=='0')push1(las,i-1),push1(i,i),las=i+1;
		push1(las,n),las=1;
		for(int i=1;i<=n;i++)if(t2[i]=='0')push2(las,i-1),push2(i,i),las=i+1;
		push2(las,n);
		for(int i=1;i<=n;i++)
		{
			if(s10[bel1[i]]&&s20[bel2[i]])s10[bel1[i]]--,s20[bel2[i]]--,ans++;
			else if(s11[bel1[i]]&&s21[bel2[i]])s11[bel1[i]]--,s21[bel2[i]]--,ans++;
			else{
				if(s10[bel1[i]])s10[bel1[i]]--;
				if(s11[bel1[i]])s11[bel1[i]]--;
				if(s20[bel2[i]])s20[bel2[i]]--;
				if(s21[bel2[i]])s21[bel2[i]]--;
			}
		}
		cout<<ans<<endl;
	}
}
