#include<bits/stdc++.h>
using namespace std;

const int N = 5e5 + 5;
int T, n, na, nb, ans;
struct edge{int l, r, c0, c1; bool typ;} a[N], b[N];
char s0[N], s1[N], p0[N], p1[N];

inline void init(char s[], char p[], edge a[], int &na){
	na = 0;  
	for(int l = 1; l <= n;){
		a[++na] = edge{0, 0, 0, 0, 0};
		a[na].typ = (p[l] == '1');
		int r = l - 1;
		while(r < n && p[r + 1] == p[l]){
			++r;
			a[na].c0 += (s[r] == '0');
			a[na].c1 += (s[r] == '1');
		}
		a[na].l = l, a[na].r = r;
		l = r + 1;
	}
}
inline void calc(edge &A, edge &B){ 
	int l = max(A.l, B.l), r = min(A.r, B.r);
	if(l > r) return ;
	if(!A.typ && !B.typ){
		for(int i = l; i <= r; ++i) ans += (s0[i] == s1[i]);
	}
	else if(A.typ && B.typ){
		int cnt0 = min(A.c0, B.c0), cnt1 = min(A.c1, B.c1);	
		cnt0 = min(cnt0, r - l + 1), cnt1 = min(cnt1, r - l + 1 - cnt0);
		ans += cnt0 + cnt1;
		A.c0 -= cnt0, B.c0 -= cnt0, A.c1 -= cnt1, B.c1 -= cnt1;
	}
	else if(!A.typ){
		for(int i = l; i <= r; ++i)
			if(s0[i] == '0'){
				if(B.c0) --B.c0, ++ans;
			}
			else{
				if(B.c1) --B.c1, ++ans;
			}
	}
	else{
		for(int i = l; i <= r; ++i)
			if(s1[i] == '0'){
				if(A.c0) --A.c0, ++ans;
			}
			else{
				if(A.c1) --A.c1, ++ans;
			}
	}
}
signed main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	scanf("%d", &T);
	while(T--){
		scanf("%d%s%s%s%s", &n, s0 + 1, s1 + 1, p0 + 1, p1 + 1);
		ans = 0;
		init(s0, p0, a, na);
		init(s1, p1, b, nb);
		
		for(int i = 1, j = 1; i <= na; ++i){
//			cout << i << ":\n";
			while(j <= nb && b[j].l <= a[i].r){
				calc(a[i], b[j]);
//				cout << j << ' ';
				++j;
			}
//			cout << endl;
			--j;
		}
		printf("%d\n", ans);
	}
	return 0;
}
