#include<bits/stdc++.h>
using namespace std;
const int N=2e5+6;
inline void read(int &x){
	char ch=getchar();
	int q=1;x=0;
	while(ch<'0'||ch>'9'){
		if(ch=='-'){
			q=-1;
		}
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=x*10+(ch-'0');
		ch=getchar();
	}
	x=x*q;
	return;
}
struct line{
	int l,r,cnt_0,cnt_1;
	void clear(){
		l=r=cnt_0=cnt_1=0;
		return;
	}
}sub1[N],sub2[N];
int len1,len2;
string s1,s2,t1,t2;
int n;
void make(){
	len1=1;
	sub1[len1].l=0;
	for(int i=1;i<=n;i++){
		if(t1[i-1]=='0'){
			sub1[len1].r=i-2;//last
			
			len1++;//only
			sub1[len1].l=sub1[len1].r=i-1;
			if(s1[i-1]=='1'){
				sub1[len1].cnt_1++;
			}else{
				sub1[len1].cnt_0++;
			}
			
			len1++;//now
			sub1[len1].l=i;
		}else{
			if(s1[i-1]=='1'){
				sub1[len1].cnt_1++;
			}else{
				sub1[len1].cnt_0++;
			}
		}
	}
	sub1[len1].r=n-1;
	len2=1;
	sub2[len2].l=0;
	for(int i=1;i<=n;i++){
		if(t2[i-1]=='0'){
			sub2[len2].r=i-2;
			
			len2++;
			sub2[len2].l=sub2[len2].r=i-1;
			if(s2[i-1]=='1'){
				sub2[len2].cnt_1++;
			}else{
				sub2[len2].cnt_0++;
			}
			
			len2++;//now
			sub2[len2].l=i;
		}else{
			if(s2[i-1]=='1'){
				sub2[len2].cnt_1++;
			}else{
				sub2[len2].cnt_0++;
			}
		}
	}
	sub2[len2].r=n-1;
	return;
}
int work(){
	int res=0,cnt_0_point,cnt_1_point;
	for(int i=1,j=1;i<=len1&&j<=len2;){
		while(i<=len1&&sub1[i].l>sub1[i].r){
			i++;
		}
		while(j<=len2&&sub2[j].l>sub2[j].r){
			j++;
		}
		
		cnt_0_point=min(sub1[i].cnt_0,sub2[j].cnt_0);
		cnt_1_point=min(sub1[i].cnt_1,sub2[j].cnt_1);
		
		int lenth=min(sub1[i].r,sub2[j].r)-sub1[i].l+1;
		if(cnt_0_point+cnt_1_point>lenth){
			res=res+lenth;
			sub1[i].cnt_1-=min(lenth,min(sub1[i].cnt_1,sub2[j].cnt_1));
			sub2[j].cnt_1-=min(lenth,min(sub1[i].cnt_1,sub2[j].cnt_1));
			sub1[i].cnt_0-=min(lenth,min(sub1[i].cnt_0,sub2[j].cnt_0));
			sub2[j].cnt_0-=min(lenth,min(sub1[i].cnt_0,sub2[j].cnt_0));
		}else{
			res=res+cnt_0_point+cnt_1_point;
			
			sub1[i].cnt_1-=cnt_1_point;
			sub2[j].cnt_1-=cnt_1_point;
			sub1[i].cnt_0-=cnt_0_point;
			sub2[j].cnt_0-=cnt_0_point;
		}
		
		sub1[i].l=sub2[j].l=min(sub1[i].r,sub2[j].r)+1;
		
		while(i<=len1&&sub1[i].l>sub1[i].r){
			i++;
		}
		while(j<=len2&&sub2[j].l>sub2[j].r){
			j++;
		}
	}
	return res;
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	read(T);
	while(T--){
		read(n);
		for(int i=0;i<=N-5;i++){
			sub1[i].clear();
			sub2[i].clear();
		}
		cin>>s1>>s2>>t1>>t2;
		make();
		cout<<work()<<"\n";
	}
	return 0;
}
