#include<iostream>
#include<iomanip>
#include<vector>
#include<cstring>
using namespace std;
void slove(){
	int n;
	cin>>n;
	string a,b,c,d;
	cin>>a>>b>>c>>d;
	a = ' ' + a;
	b = ' ' + b;
	c = ' ' + c;
	d = ' ' + d;
	bool flag = true;
	for (int i = 2;i <= n;i++){
		if (a[i] != a[i - 1]){
			flag = false;
		}
	}
	if (flag){
		//xingzhi A
		int ans = 0;
		for (int i = 1;i <= n;i++){
			if (a[i] == b[i]){
				ans++;
			}
		}
		cout<<ans<<'\n';
		return ;
	}
	flag = true;
	for (int i = 1;i <= n;i++){
		if (c[i] != d[i]){
			flag = false;
		}
	}
	if (flag){
		//xingzhi B
		pair <int,int> cnt1,cnt2;
		cnt1.first = cnt1.second = cnt2.first = cnt2.second = 0;
		int ans = 0;
		for (int i = 1;i <= n;i++){
			if (c[i] == '0'){
				ans += min(cnt1.first,cnt2.first) + min(cnt1.second,cnt2.second);
				ans += (a[i] == b[i]);
				cnt1.first = cnt1.second = cnt2.first = cnt2.second = 0;
			}
			else{
				if (a[i] == '1'){
					cnt1.first++;
				}
				else{
					cnt1.second++;
				}
				if (b[i] == '1'){
					cnt2.first++;
				}
				else{
					cnt2.second++;
				}
			}
		}
		ans += min(cnt1.first,cnt2.first) + min(cnt1.second,cnt2.second);
		cout<<ans<<'\n';
		return ;
	}
	int x = 0,y = 0,id = 0,di = 0;
	for (int i = 1;i <= n;i++){
		if (c[i] == '0'){
			x++;
			id = i;
		}
		if (d[i] == '0'){
			y++;
			di = i;
		}
	}
	if (x == 1 && y == 1){
		//xingzhi C
		int ans = 0,cnt0 = 0,cnt1 = 0,qwq1 = 0,qwq2 = 0,awa1 = 0,awa2 = 0;
		if (id < di){
			for (int i = 1;i < di;i++){
				if (b[i] == '0'){
					cnt0++;
				}
				else{
					cnt1++;
				}
			}
			for (int i = 1;i <= id;i++){
				if (a[i] == '0'){
					if (cnt0 > 0){
						cnt0--;
					}
					else{
						qwq1++;
					}
				}
				else{
					if (cnt1 > 0){
						cnt1--;
					}
					else{
						awa1++;
					}
				}
			}
			cnt0 = cnt1 = 0;
			for (int i = id + 1;i <= n;i++){
				if (a[i] == '0'){
					cnt0++;
				}
				else{
					cnt1++;
				}
			}
			for (int i = di;i <= n;i++){
				if (b[i] == '0'){
					if (cnt0 > 0){
						cnt0--;
					}
					else{
						qwq2++;
					}
				}
				else{
					if (cnt1 > 0){
						cnt1--;
					}
					else{
						awa2++;
					}
				}
			}
		}
		else{
			for (int i = 1;i < id;i++){
				if (a[i] == '0'){
					cnt0++;
				}
				else{
					cnt1++;
				}
			}
			for (int i = 1;i <= di;i++){
				if (b[i] == '0'){
					if (cnt0 > 0){
						cnt0--;
					}
					else{
						qwq2++;
					}
				}
				else{
					if (cnt1 > 0){
						cnt1--;
					}
					else{
						awa2++;
					}
				}
			}
			cnt0 = cnt1 = 0;
			for (int i = di + 1;i <= n;i++){
				if (b[i] == '0'){
					cnt0++;
				}
				else{
					cnt1++;
				}
			}
			for (int i = id;i <= n;i++){
				if (a[i] == '0'){
					if (cnt0 > 0){
						cnt0--;
					}
					else{
						qwq1++;
					}
				}
				else{
					if (cnt1 > 0){
						cnt1--;
					}
					else{
						awa1++;
					}
				}
			}
		}
		pair <int,int> cntx,cnty;
		cntx.first = cntx.second = cnty.first = cnty.second = 0;
		for (int i = min(id,di) + 1;i < max(id,di);i++){
			if (a[i] == '1'){
				cntx.first++;
			}
			else{
				cntx.second++;
			}
			if (b[i] == '1'){
				cnty.first++;
			}
			else{
				cnty.second++;
			}
		}
		ans += min(cntx.first - awa1,cnty.first - awa2) + min(cntx.second - qwq1,cnty.second - qwq2);
		cout<<ans<<'\n';
		return ;
	}
	srand(time(0) * n + 7);
	cout<<(1LL * rand() * rand()) % n + 1<<'\n';
}

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin>>t;
	while (t--){
		slove();
	}
	return 0;
}
