#include <bits/stdc++.h>
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
using namespace std;

const int N=1e5+7;
int n;
char s0[N],s1[N],t0[N],t1[N];
deque<pii> q0,q1;
void Subt(){
	scanf("%d",&n);
	scanf("%s%s%s%s",s0+1,s1+1,t0+1,t1+1);
	t0[n+1]=t1[n+1]='0';
	while(!q0.empty()) q0.pop_front();
	while(!q1.empty()) q1.pop_front();
	int cc0=0,cc1=0;
	for(int i=1;i<=n;i++){
		if(s0[i]=='0') cc0++;
		else cc1++;
		if(t0[i]!='1'||t0[i+1]!='1'){
			q0.push_back(mkp(cc0,cc1));
			cc0=cc1=0;
		}  
	}
	for(int i=1;i<=n;i++){
		if(s1[i]=='0') cc0++;
		else cc1++;
		if(t1[i]!='1'||t1[i+1]!='1'){
			q1.push_back(mkp(cc0,cc1));
			cc0=cc1=0;
		}  
	}
	int r=0;
	while(!q0.empty()&&!q1.empty()){
		pii fr0=q0.front(),fr1=q1.front();
		q0.pop_front(),q1.pop_front();
		int cc0=min(fr0.fi,fr1.fi);
		int cc1=min(fr0.se,fr1.se);
		r+=cc0+cc1;
		if(fr0.fi+fr0.se<fr1.fi+fr1.se){
			int C=fr1.fi+fr1.se-fr0.fi-fr0.se;
			fr1.fi-=cc0,fr1.se-=cc1;
			fr1.fi=min(fr1.fi,C);
			fr1.se=min(fr1.se,C);
			q1.push_front(fr1);
		}else if(fr0.fi+fr0.se>fr1.fi+fr1.se){
			int C=fr0.fi+fr0.se-fr1.fi-fr1.se;
			fr0.fi-=cc0,fr0.se-=cc1;
			fr0.fi=min(fr0.fi,C);
			fr0.se=min(fr0.se,C);
			q0.push_front(fr0);
		}
	}
	printf("%d\n",r);
}
signed main(){
	freopen("edit.in" ,"r",stdin );
	freopen("edit.out","w",stdout);
	int T=1;
	scanf("%d",&T);
	while(T--) Subt();
	return 0;
} 
