#include <bits/stdc++.h> 
using namespace std;
const int maxn = 1e6+10;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<int,int> pii;
int T;
int n;
string s;
int a[maxn],b[maxn];
int t1[maxn],t2[maxn];
int a1[maxn],a0[maxn],b1[maxn],b0[maxn];
int posa[maxn],posb[maxn],cnta,cntb;
void init(){
	memset(a1,0,sizeof(a1));
	memset(a0,0,sizeof(a0));
	memset(b1,0,sizeof(b1));
	memset(b0,0,sizeof(b0));
	cnta = 0,cntb = 0;
	for(int i = 1; i <= n; i++){
		if(t1[i]){
			a1[i] = a1[i-1],a0[i] = a0[i-1];
			if(a[i]){
				a1[i]++;
			}else{
				a0[i]++;
			}
		}else{
			a1[i] = 0,a0[i] = 0;
			posa[++cnta] = i;
		} 
		if(t2[i]){
			b1[i] = b1[i-1],b0[i] = b0[i-1];
			if(b[i]){
				b1[i]++;
			}else{
				b0[i]++;
			}
		}else{
			b1[i] = 0,b0[i] = 0;
			posb[++cntb] = i;
		}
	}

	if(posb[cntb] < n)
		posb[++cntb] = n+1;
	if(posa[cnta] < n)
		posa[++cnta] = n+1;
	
}
/*
1
10
0110111100
1111111100
1110000100
0110111011

8
*/
void solve(){
	int ans = 0;
	int j = 0;
	for(int i = 1; i <= cnta; i++){
		//cout << "*" << posa[i] << " ";
		int nw1 = a1[posa[i]-1],nw0 = a0[posa[i]-1];
		//cout << nw1<<" " << nw0 << endl;
		for(;j+1 <= cntb && posb[j+1] < posa[i];){
			j++;	
			if(posb[j] <= posa[i-1]) continue;
			ans += min(nw1,b1[posb[j]-1]);
			ans += min(nw0,b0[posb[j]-1]);
			nw1 -= min(nw1,b1[posb[j]-1]),nw0 -= min(nw0,b0[posb[j]-1]);
			if(posb[j] <= n && b[posb[j]] == 1 && nw1 > 0){
				nw1--;
				ans++;
			}
			if(posb[j] <= n && b[posb[j]] == 0 && nw0 > 0){
				nw0--;
				ans++;
			}
		}
		if(posb[j+1] == posa[i]){
				j++;
				ans += min(nw1,b1[posb[j]-1]);
				ans += min(nw0,b0[posb[j]-1]);
				b1[posb[j]-1] -= min(nw1,b1[posb[j]-1]);
				b0[posb[j]-1] -= min(nw0,b0[posb[j]-1]);
				if(a[posa[i]] == b[posb[j]]) ans++;
		} else if(posb[j+1] > posa[i]){
			if(a[posa[i]] == 1) nw1++;
			else if(a[posa[i]] == 0) nw0++;
			ans += min(nw1,b1[posb[j+1]-1]);
			ans += min(nw0,b0[posb[j+1]-1]);
			b1[posb[j+1]-1] -= min(nw1,b1[posb[j+1]-1]);
			b0[posb[j+1]-1] -= min(nw0,b0[posb[j+1]-1]);
		}
	}
	cout << ans << endl;
}
int main(){
	//edit assign traverse query
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> T;
	while(T--){
		cin >> n;
		cin >> s;
		for(int i = 0; i < n; i++){
			a[i+1] = s[i]-'0';
		}
		cin >> s;
		for(int i = 0; i < n; i++){
			b[i+1] = s[i]-'0';
		}
		a[n+1] = 100;
		b[n+1] = 1100;
		a[0] = 110;
		b[0] = 101;
		cin >> s;
		for(int i = 0; i < n; i++){
			t1[i+1] = s[i]-'0';
		}
		cin >> s;
		for(int i = 0; i < n; i++){
			t2[i+1] = s[i]-'0';
		}
		init();
		solve();
	}
	return 0;
}
