#include<bits/stdc++.h>
using namespace std;
string a, b, c, d;
int n, T, an[114514], bnu[114514], break_over_a[114514], getsum, break_over_b[114514], bns[114514], al, bl, aone, az, bone, bz, ans;
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	cin >> T;
	for(int k = 1; k <= T; k++){
		cin >> n;
		cin >> a >> b >> c >> d;
		ans = 0;
		bone = bz = aone = az = 0; 
		al = bl = 1;
		for(int i = 1; i <= n; i++){
			an[i] = a[i - 1] - '0';
			bnu[i] = b[i - 1] - '0';
			bns[i] = bnu[i] + bns[i - 1];
			if(c[i - 1] == '0'){
				break_over_a[al] = i;
				al++;
			}
			if(d[i - 1] == '0'){
				break_over_b[bl] = i;
				bl++;
			}
		}
		break_over_a[al] = n + 1;
		break_over_b[bl] = n + 1;
		int apos = 0, alp = 1, bpos = 0, blp = 1;
		while(alp <= al && blp <= bl){
			for(int i = apos + 1; i < break_over_a[alp]; i++){
				if(c[i - 1] == '0'){
					continue;
				}
				if(an[i]){
					aone++;
				}
				else{
					az++;
				}
			}
			apos = break_over_a[alp];
			for(int i = bpos + 1; i < break_over_b[blp]; i++){
				if(d[i - 1] == '0'){
					continue;
				}
				if(bnu[i]){
					bone++;
				}
				else{
					bz++;
				}
			}
			bpos = break_over_b[blp]; 
			if(bpos > apos){
				if(aone <= bone){
					ans += aone;
					bone -= aone;
					aone = 0;
				}
				else{
					ans += bone;
					bone = aone = 0;
				}
				if(bz >= az){
					ans += az;
					bz -= az;
					az = 0;
				}
				else{
					ans += bz;
					bz = az = 0;
				}
				if(!an[apos] && bz){
					bz--;
					ans++;
				}
				else if(an[apos] && bone){
					bone--;
					ans++; 
				}
				if(bpos == apos + 1){
					bone = 0, bz = 0;
				}
				alp++;
			}
			else if(bpos < apos){
				if(aone >= bone){
					ans += bone;
					aone -= bone;
					bone = 0;
				}
				else{
					ans += aone;
					aone = bone = 0;
				}
				if(bz <= az){
					ans += bz;
					az -= bz;
					bz = 0;
				}
				else{
					ans += az;
					bz = az = 0;
				}
				if(!bnu[bpos] && az){
					az--;
					ans++;
				}
				else if(bnu[bpos] && aone){
					aone--;
					ans++; 
				}
				if(apos == bpos + 1){
					aone = 0, az = 0;
				}
				blp++;
			}
			else if(bpos == apos){
				ans += min(aone, bone) + min(az, bz);
				if(bnu[bpos] == an[apos] && apos != n + 1){
					ans++;
				}
				bone = bz = aone = az = 0;
				alp++;
				blp++;
			}
		}
		cout << ans << '\n';
	}
	return 0;
} 
