#include <iostream>
#include <utility>

using namespace std;
using lint=long long;
const int maxn=1e5+18;

char buf[1<<20], *p1, *p2;
#define getc() (p1==p2 && (p2=(p1=buf)+fread(buf, 1, 1<<20, stdin))==p1? EOF:*p1++)
using in_t =int;
in_t read(in_t ret=0, char c=0){
	while ('9'<c||c<'0') c=getc();
	while ('0'<=c&&c<='9')
		ret=ret*10+(c^48), c=getc();
	return ret;
}

int gstr(char s[], int i=0, char c=0){
	while (c<=' ') c=getc();
	while (c>' ') s[++i]=c, c=getc();
	return i;
}

int n;
char a[maxn], b[maxn];
char ta[maxn], tb[maxn];
int apre0[maxn], apre1[maxn], bpre0[maxn], bpre1[maxn];

int main(){
	int i, j, k, u, v;
	cout.tie(0), ios::sync_with_stdio(0);
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	int t=read();
	while (t--){
		n=read(), gstr(a), gstr(b), gstr(ta), gstr(tb);
		
		int flag=1;
		for (i=1; i<=n; ++i){
			if (ta[i]!=tb[i]) flag=0;
			apre0[i]=apre0[i-1], apre1[i]=apre1[i-1];
			bpre0[i]=bpre0[i-1], bpre1[i]=bpre1[i-1];
			++(a[i]=='0'? apre0[i] : apre1[i]);
			++(b[i]=='0'? bpre0[i] : bpre1[i]);
		}
		
		int ans; ans=0;
		if (apre0[n]==0){//A
			cout<<bpre1[n]<<'\n';
			continue;
		} else if (apre1[n]==0){//A
			cout<<bpre0[n]<<'\n';
			continue;
		} else if (flag){//B
			for (i=j=1; i<=n; ++i){
				if (ta[i+1]!=ta[i]){
					if (ta[i]=='1'){
						ans+=
							min(apre0[i]-apre0[j-1], bpre0[i]-bpre0[j-1])+
							min(bpre1[i]-bpre1[j-1], apre1[i]-apre1[j-1]);
					} j=i+1;
				}
			}
			cout<<ans<<'\n';
			continue;
		}
		
		int cnta1=0, cntb1=0;
		int cnta0=0, cntb0=0;
		int exc0=0, exc1=0;
		int stac=0;
		i=j=1, u=v=1;
		while (i<n || u<n){
			if (ta[j]=='1'){
				while (1){
					++(a[i]=='0'? cnta0 : cnta1);
					if (i+1<=n || ta[i]==ta[i+1]) ++i;
					else break;
				} while (1){
					while (1){
						++(b[u]=='0'? exc0 : exc1);
						if (u+1<=n || tb[u]==tb[u+1]) ++u;
						else break;
					} if (u+1>i) break;
					else{
						v=++u;
						cntb1+=exc1, cntb0+=exc0;
						exc1=exc0=0;
					}
				}
				ans+=min(cnta1, cntb1)+min(cnta0, cntb0);
				cnta1=max(0, cnta1-cntb1);
				cnta0=max(0, cnta0-cntb0);
				if (tb[v]=='0'){
					int d1=min(cnta1, bpre1[i]-bpre1[v-1]);
					int d0=min(cnta0, bpre0[i]-bpre0[v-1]);
					ans+=d1+d0, exc1-=d1, exc0-=d0;
				} else {
					int d1=min(cnta1, exc1);
					int d0=min(cnta0, exc0);
					ans+=d1+d0;
					exc0=max(0, exc0-cnta0);
					exc1=max(0, exc1-cnta1);
				}
			} else {
				while (i<=n && ta[i]==ta[i+1]) ++i; 
				while (1){
					while (1){
						if (tb[u]=='1') ++(b[u]=='0'? exc0 : exc1);
						else stac+=(a[u]==b[u]);
						if (u+1<=n || tb[u]==tb[u+1]) ++u;
						else break;
					} if (u+1>i) break;
					else{
						ans+=stac;
						int d1=min(apre1[u]-apre1[v-1], exc1);
						int d0=min(apre0[u]-apre0[v-1], exc0);
						ans+=d1+d0, exc1=exc0=stac=0, v=++u;
					}
				}
			}
			cnta1=cnta0=stac=0, 
			v=j=++i;
		}
		
		cout<<ans<<'\n';
	}
	
	return 0;
}
