#include<bits/stdc++.h>
using namespace std;
//#define int long long
string a,b,c,d;
int t,n; 
struct az{
	int l;
	int r;
	int ling;
	int yi; 
};
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> t;
	while(t--){
		cin >> n;
		cin >> a;
		cin >> b;
		cin >> c;
		cin >> d;
		vector<az> op;
		int left = 0,right = 0,flag1 = 1,flag = 0,l = 0,y = 0,cnt1 = 0,ans = 0;
		for(int i = 0; i < n; i++){
			if(a[i] != a[i-1])	flag1 = 0;
			if(c[i] == '1'){
				if(a[i] == '1')	y++;
				else	l++;
				if(!flag){
					flag = 1;
					left = i;
				}
				right = i;
			}else{
				if(left != right&&flag){
					az o;
					o.l = left;
					o.r = right;
					o.ling = l;
					o.yi = y;
					op.push_back(o);
					cnt1++;
//					//cout << "qwefqf " << cnt1;//cout <<endl;
				}else{
					c[i-1] = '0';
				}
				flag = y = l = left = right = 0;
			}
		}
		if(left != right&&flag){
			az o;
			o.l = left;
			o.r = right;
			o.ling = l;
			o.yi = y;
			op.push_back(o);
			cnt1++;
		}
//		for(int i = 0; i < cnt1; i++){
//			//cout << op[i].l << " - " << op[i].r << " 0: " << op[i].ling << " 1: " << op[i].yi <<endl;
//		}
		vector<az> po;
		left = right = flag = l = y = 0;
		int cnt2 = 0;
		for(int i = 0; i < n; i++){
			if(flag1 == 1){
				if(b[i] == a[1])	ans++;
			}
			if(d[i] == '1'){
				if(b[i] == '1')	y++;
				else	l++;
				if(!flag){
					left = i;
					flag = 1;
				}
				right = i;
			}else{
				if(left != right&&flag){
					az o;
					o.l = left;
					o.r = right;
					o.ling = l;
					o.yi = y;
					po.push_back(o);
					cnt2++;
				}else{
					d[i-1] = '0';
				}
				flag = y = l = left = right = 0;
			}
		}
		if(flag1){
			cout << ans <<endl;
			continue;
		}
		if(left != right&&flag){
			az o;
			o.l = left;
			o.r = right;
			o.ling = l;
			o.yi = y;
			po.push_back(o);
			cnt2++;
		}
//		for(int i = 0; i < cnt2; i++){
//			//cout << po[i].l << " - " << po[i].r << " 0: " << po[i].ling << " 1: " << po[i].yi <<endl;
//		}
		left = 0;
		for(int i = 0; i < n; i++){
			if(c[i] == '0'){
				while(left+1 < cnt2&&po[left+1].l <= i)	left++;
				if(po[left].r < i){
					if(b[i] == a[i]){
						if(a[i] == '1')	a[i] = '0';
						else	a[i] = '1';
						ans++;
					}
					continue;
				}
				if(po[left].r >= i){
					if(a[i] == '1'&&po[left].yi){
						po[left].yi--;
						ans++;
					}else{
						if(a[i] == '0'&&po[left].ling){
							po[left].ling--;
							ans++;
						}
					}
				}
			}
		}
		//cout << ans <<endl;
		left = 0;
		for(int i = 0; i < n; i++){
			if(d[i] == '0'){
				while(left+1 < cnt1&&op[left+1].l <= i)	left++;
				if(op[left].r < i){
					if(b[i] == a[i])	ans++;
					continue;
				}	
				if(op[left].r >= i){
					if(b[i] == '1'&&op[left].yi){
						op[left].yi--;
						ans++;
					}else{
						if(b[i] == '0'&&op[left].ling){
							op[left].ling--;
							ans++;
						}
					}
				}
			}
		}
		//cout << ans <<endl;
		left = 0;
		for(int i = 0; i < cnt1; i++){
			while(left+1 < cnt2&&po[left].r < op[i].l)	left++;
			if(po[left].l > op[i].r)	continue;
			if(po[left].ling < op[i].ling){
				op[i].ling -= po[left].ling;
				ans += po[left].ling;
				po[left].ling = 0;
			}else{
				po[left].ling -= op[i].ling;
				ans += op[i].ling;
				op[i].ling = 0;
			}
			if(po[left].yi < op[i].yi){
				op[i].yi -= po[left].yi;
				ans += po[left].yi;
				po[left].yi = 0;
			}else{
				po[left].yi -= op[i].yi;
				ans += op[i].yi;
				op[i].yi = 0;
			}
		}
		left = 0;
		for(int i = 0; i < cnt2; i++){
			while(left+1 < cnt1&&op[left].r < po[i].l)	left++;
			if(op[left].l > po[i].r)	continue;
			if(op[left].ling < po[i].ling){
				po[i].ling -= op[left].ling;
				ans += op[left].ling;
				op[left].ling = 0;
			}else{
				op[left].ling -= po[i].ling;
				ans += po[i].ling;
				po[i].ling = 0;
			}
			if(op[left].yi < po[i].yi){
				po[i].yi -= op[left].yi;
				ans += op[left].yi;
				op[left].yi = 0;
			}else{
				op[left].yi -= po[i].yi;
				ans += po[i].yi;
				po[i].yi = 0;
			}
		}
		cout << ans <<endl;
	}
	return 0;
}/*
1
9
101111111
100111000
110111011
011111111

*/
