#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#include<cmath>
#define LL long long
#define ULL unsigned long long
using namespace std;
const int N=1e5+7;
const int INF=0x3f3f3f3f;
int a[N],b[N],ca[N],cb[N];
struct node{
	int num0,num1;
};
node as[N],bs[N];
int qa[N],qb[N],topa,topb,ta[N],tb[N];
int t,n;
int flagb=1;
void init(){
	string at;
	cin >> at;
	for(int i=1;i<=n;i++){
		a[i]=at[i-1]-'0';
		if(a[i]==1){
			as[i].num0=as[i-1].num0;
			as[i].num1=as[i-1].num1+1;
		}else{
			as[i].num0=as[i-1].num0+1;
			as[i].num1=as[i-1].num1;
		}
	}
	cin >> at;
	for(int i=1;i<=n;i++){
		b[i]=at[i-1]-'0';
		if(b[i]==1){
			bs[i].num0=bs[i-1].num0;
			bs[i].num1=bs[i-1].num1+1;
		}else{
			bs[i].num0=bs[i-1].num0+1;
			bs[i].num1=bs[i-1].num1;
		}
	}
	cin >> at;
	for(int i=1;i<=n;i++){
		ca[i]=at[i-1]-'0';
		if(ca[i]==0)qa[++topa]=i;
		ta[i]=qa[topa];
	}
	cin >> at;
	for(int i=1;i<=n;i++){
		cb[i]=at[i-1]-'0';
		if(cb[i]==0&&cb[i]!=ca[i]){
			flagb=0;
		}
		if(cb[i]==0)qb[++topb]=i;
		tb[i]=qb[topb];
	}
	
}
int normal(int l,int r){
	node ta,tb;
	if(l>r)return 0;
//	cout << "lr:" << l << " " << r << endl;
	ta.num0=as[r].num0-as[l-1].num0;
	ta.num1=as[r].num1-as[l-1].num1; 
//	cout << "ta:" << ta.num0 << " " << ta.num1 << endl; 
	tb.num0=bs[r].num0-bs[l-1].num0;
	tb.num1=bs[r].num1-bs[l-1].num1;
//	cout << "tb:" << tb.num0 << " " << tb.num1 << endl;
	
	return min(ta.num0,tb.num0)+min(ta.num1,tb.num1);
}
void cleangogo(){
	topa=topb=0;
	memset(qa,0,sizeof(qa));
	memset(qb,0,sizeof(qb));
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		init();
		int ans=0;
		for(int i=1;i<=n;i++){
			if(a[i]==b[i]){
				ans++;
			}
		}
		if(ans==n){
			printf("%d\n",ans);
		}else{
			ans=0;
			if(flagb){
//				cout << "BAKA\n";
				for(int i=1;i<=topa;i++){
					if(a[qa[i]]==b[qb[i]]){
						ans++;
//						cout << qa[i] << " " << qb[i] << " " << a[qa[i]] << " " << b[qb[i]] << endl;
					}
					ans+=normal(qa[i-1]+1,qa[i]-1);
				}
				printf("%d\n",ans);
			}else{
				printf("%d\n",normal(1,n));
			} 
		}
		cleangogo(); 
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

