#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=(a);i<=(b);i++)
#define F_(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll;
const int N = 1e5+10;
int t,n,ans;
string s1,s2,t1,t2;
void found(string s,string p,int &x,int &suml,int &sumy){
	while (x<=n&&p[x]=='1'){
		if (s[x]=='0') suml++;
		else sumy++;
		x++;
	}
	x--;
}
void work(){
	ans=0;
	cin >> n;
	cin>>s1>>s2>>t1>>t2;
	s1=" "+s1,s2=" "+s2,t1=" "+t1,t2=" "+t2;
	int p1=1,p2=1,suml1=0,suml2=0,sumy1=0,sumy2=0;
	bool fg1=0,fg2=0;
	while (p1<=n&&p2<=n){
		if (fg1==0){suml1=sumy1=0;found(s1,t1,p1,suml1,sumy1);}
		if (fg2==0){suml2=sumy2=0;found(s2,t2,p2,suml2,sumy2);}
		//printf("%d %d %d %d %d %d\n",p1,p2,suml1,sumy1,suml2,sumy2);
		int mal=min(suml1,suml2);
		int may=min(sumy1,sumy2);
		ans += mal+may;
		suml1-=mal,suml2-=mal,sumy1-=may,sumy2-=may;
		if (p1==p2){
			p1++,p2++;
			if (p1>n) break;
			if (s1[p1]==s2[p2]) ans++;
		} else if (p1<p2){
			p1++;
			if (s1[p1]=='0'){
				if (suml2>=1) suml2--,ans++;
			} else {
				if (sumy2>=1) sumy2--,ans++;
			}
		} else {
			p2++;
			if (s2[p2]=='0'){
				if (suml1>=1) suml1--,ans++;
			} else {
				if (sumy1>=1) sumy1--,ans++;
			}
		}
		if (p1==p2) fg1=0,fg2=0,p1++,p2++;
		else if (p1<p2) fg1=0,fg2=1,p1++;
		else fg1=1,fg2=0,p2++; 
	}
	printf("%d\n",ans);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> t;
	while (t--) work();
	return 0;
}
