#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>
#include<queue>
#include<map>
#define N 100005
using namespace std;
int T,n;
string s1,s2,t1,t2;
bool ck1[N],ck2[N];
struct node{
	int l,r;
};
node huo1[N],huo2[N];
int sum1[N],summ1[N],sum2[N],summ2[N];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--){
		cin>>n>>s1>>s2>>t1>>t2;
		memset(ck1,1,sizeof(ck1));
		memset(ck2,1,sizeof(ck2));	
		memset(huo1,0,sizeof(huo1));
		memset(huo2,0,sizeof(huo2));
		memset(sum1,0,sizeof(sum1));
		memset(sum2,0,sizeof(sum2));
		memset(summ1,0,sizeof(summ1));
		memset(summ2,0,sizeof(summ2));
		int cnt1=0,cnt2=0;
		for(int i=0;i<n;i++){
			if(s1[i]=='1') cnt1++;
			if(s2[i]=='1') cnt2++;
			if(i==0){
				if(t1[i+1]=='0'||t1[i]=='0') ck1[i]=0;
				if(t2[i+1]=='0'||t2[i]=='0') ck2[i]=0;
			}
			else if(i==n-1){
				if(t1[i-1]=='0'||t1[i]=='0') ck1[i]=0;
				if(t2[i-1]=='0'||t2[i]=='0') ck2[i]=0;
			}
			else{
				if(t1[i-1]=='0'&&t1[i+1]=='0') ck1[i]=0;
				if(t2[i-1]=='0'&&t2[i+1]=='0') ck2[i]=0;
				if(t1[i]=='0') ck1[i]=0;
				if(t2[i]=='0') ck2[i]=0;
			}
		}
		int x=0,y=0;
		bool flag1=0,flag2=0;
		for(int i=0;i<n;i++){
			if(ck1[i]){
				if(!flag1){
					flag1=1;
					x++;
					huo1[x].l=i;
				}
				if(i==n-1) huo1[x].r=i;
			}
			else{
				if(flag1){
					huo1[x].r=i-1;
					flag1=0;
				}
			}
			if(ck2[i]){
				if(!flag2){
					flag2=1;
					y++;
					huo2[y].l=i;
				}
				if(i==n-1) huo2[y].r=i;
			}
			else{
				if(flag2){
					huo2[y].r=i-1;
					flag2=0;
				}
			}
		}
		for(int i=1;i<=x;i++){
			int l=huo1[i].l,r=huo1[i].r;
			for(int j=l;j<=r;j++){
				if(s1[j]=='1') sum1[i]++;
			}
			summ1[i]=r-l+1-sum1[i];
		}
		for(int i=1;i<=y;i++){
			int l=huo2[i].l,r=huo2[i].r;
			for(int j=l;j<=r;j++){
				if(s2[j]=='1') sum2[i]++;
			}
			summ2[i]=r-l+1-sum2[i];
		}
		for(int i=1;i<=x;i++){
			int l=huo1[i].l,r=huo1[i].r;
			for(int j=l;j<=r;j++){
				if(!ck2[j]){
					if(s2[j]=='0'){
						if(summ1[i]) summ1[i]--,s1[j]=s2[j];
						else s1[j]='1',sum1[i]--;
					}
					else{
						if(sum1[i]) sum1[i]--,s1[j]=s2[j];
						else s1[j]='0',summ1[i]--;
					}
				}
			}
		}
		for(int i=1;i<=x;i++){
			int l=huo1[i].l,r=huo1[i].r;
			for(int j=l;j<=r;j++){
				if(ck2[j]){
					if(s2[j]=='0'){
						if(summ1[i]) summ1[i]--,s1[j]=s2[j];
						else s1[j]='1',sum1[i]--;
					}
					else{
						if(sum1[i]) sum1[i]--,s1[j]=s2[j];
						else s1[j]='0',summ1[i]--;
					}
				}
			}
		}
		for(int i=1;i<=y;i++){
			int l=huo2[i].l,r=huo2[i].r;
			for(int j=l;j<=r;j++){
				if(s1[j]=='0'){
					if(summ2[i]) summ2[i]--,s2[j]=s1[j];
					else s2[j]='1',sum2[i]--;
				}
				else{
					if(sum2[i]) sum2[i]--,s2[j]=s1[j];
					else s2[j]='0',summ2[i]--;
				}
			}
		}
		int ans=0;
		for(int i=0;i<n;i++){
			if(s1[i]==s2[i]) ans++;
		}
		cout<<ans<<endl;
	}
	return 0;
}

