#include<bits/stdc++.h>
using namespace std;

const int N=1e5+5;
int t,n,x[N],y[N],ans;
char op;
priority_queue<int,vector<int>,greater<int> >a,b,c,d;
void f(int pos1,int pos2,int now){
	if(pos1==0){
		if(!b.empty()&&x[now]>b.top()){
			++ans;
			a.emplace(b.top());
			b.pop();
			return;
		}
	}
	else{
		if(!a.empty()&&x[now]>a.top()){
			++ans;
			b.emplace(a.top());
			a.pop();
			return;
		}
	}
	if(pos2==0){
		if(!d.empty()&&y[now]>d.top()){
			++ans;
			c.emplace(d.top());
			d.pop();
			return;
		}
	}
	else{
		if(!c.empty()&&y[now]>c.top()){
			++ans;
			d.emplace(c.top());
			c.pop();
			return;
		}
	}	
}
void work(int now){
	int pos1,pos2;
	if(!a.empty()&&a.top()==now) pos1=0,a.pop();
	else pos1=1,b.pop();
	if(!c.empty()&&c.top()==now) pos2=0,c.pop();
	else pos2=1,d.pop();
	if(pos1==pos2){
		++ans;
		return;
	}
	f(pos1,pos2,now);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>t;
	while(t--){
		ans=0;
		cin>>n;
		for(int i=1;i<=n;++i){
			cin>>op;
			if(op=='0') a.emplace(i);
			else b.emplace(i);
		}
		for(int i=1;i<=n;++i){
			cin>>op;
			if(op=='0') c.emplace(i);
			else d.emplace(i);
		}
		for(int i=1;i<=n;++i){
			cin>>op;
			if(op=='0') x[i]=i;
			else x[i]=i+1;
		}
		for(int i=1;i<=n;++i){
			cin>>op;
			if(op=='0') y[i]=i;
			else y[i]=i+1;
		}
		for(int i=n-1;i;--i) x[i]=x[x[i]],y[i]=y[y[i]];
		for(int i=1;i<=n;++i) work(i);
		cout<<ans<<"\n";
	}
	return 0;
} 
