// 1<=t<=10 1<=n<=1e5
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+5;

int prea1[MAXN],prea0[MAXN],preb1[MAXN],preb0[MAXN];
vector<int> v1,v2; 

int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin >> t;
	while (t--){
		v1.clear();
		v2.clear();
		int n;
		cin >> n;
		string s1,s2,s3,s4;
		cin >> s1 >> s2 >> s3 >> s4;
		s1=" "+s1,s2=" "+s2,s3=" "+s3,s4=" "+s4;
		int summ1=0,summ2=0;
		for (int i=1;i<=n;i++) summ1+=(s3[i]=='0'),summ2+=(s4[i]=='0');
		bool fg=1;
		for (int i=2;i<=n;i++) if (s1[i]!=s1[1]) fg=0;
		if (fg){
			int sum1=0,sum2=0;
			for (int i=1;i<=n;i++) if (s2[i]=='0') sum1++; else sum2++;
			cout << (s1[1]=='0'?sum1:sum2) << endl; 
		}
		else if (s3==s4){
			int sum1=0,sum2=0,sum3=0,sum4=0,ans=0;
			for (int i=1;i<=n;i++){
				if (s3[i]=='0'){
					ans+=min(sum1,sum3)+min(sum2,sum4);
					ans+=(s1[i]==s2[i]);
					sum1=sum2=sum3=sum4=0;
				}
				else{
					if (s1[i]=='0') sum1++; else sum2++;
					if (s2[i]=='0') sum3++; else sum4++;
				}
			}
			cout << ans << endl;
		}
		else if (summ1==1 and summ2==1){
			int id1=0;
			for (int i=1;i<=n;i++) if (s3[i]=='0'){
				id1=i;
				break;
			}
			int id2=0;
			for (int i=1;i<=n;i++) if (s4[i]=='0'){
				id2=i;
				break;
			}
			if (id1>id2){
				swap(s1,s2);
				swap(s3,s4);
				swap(id1,id2);
			}
			int sum1=0,sum2=0,sum3=0,sum4=0,ans=0;
			for (int i=1;i<id1;i++){
				if (s1[i]=='0') sum1++; else sum2++;
				if (s2[i]=='0') sum3++; else sum4++;
			}
			for (int i=id1;i<id2;i++)
				if (s2[i]=='0') sum3++; else sum4++;
			ans+=min(sum1,sum3)+min(sum2,sum4);
			sum3=max(0,sum3-sum1);
			sum4=max(0,sum4-sum2);
			if (s1[id1]=='0' and sum3) sum3--,ans++;
			if (s1[id1]=='1' and sum4) sum4--,ans++;
			sum1=sum2=0;
			for (int i=id1+1;i<=n;i++)
				if (s1[i]=='0') sum1++; else sum2++;
			ans+=min(sum1,sum3)+min(sum2,sum4);
			sum1=max(0,sum1-sum3);
			sum2=max(0,sum2-sum4);
			if (s2[id2]=='0' and sum1) sum1--,ans++;
			if (s2[id2]=='1' and sum2) sum2--,ans++;
			sum3=sum4=0;
			for (int i=id2+1;i<=n;i++)
				if (s2[i]=='0') sum3++; else sum4++;
			ans+=min(sum1,sum3)+min(sum2,sum4);
			cout << ans << endl;
		}
		else{
			for (int i=1;i<=n;i++) prea1[i]=prea1[i-1]+(s1[i]=='1'),prea0[i]=prea0[i-1]+(s1[i]=='0');
			for (int i=1;i<=n;i++) preb1[i]=preb1[i-1]+(s2[i]=='1'),preb0[i]=preb0[i-1]+(s2[i]=='0');
			int las=0,ans=0;
			for (int i=1;i<=n;i++){
				if (s3[i]=='0') v1.push_back(i);
				if (s4[i]=='0') v2.push_back(i);
			}
			v1.push_back(n+1),v2.push_back(n+1);
			for (int i=1;i<=n;i++){
				int tmpp=ans;
				if (s3[i]=='0' and s4[i]=='0'){
					ans+=min(prea1[i-1]-prea1[las],preb1[i-1]-preb1[las]);
					ans+=min(prea0[i-1]-prea0[las],preb0[i-1]-preb0[las]);
					ans+=(s1[i]==s2[i]);
				}
				else if (s3[i]=='0'){
					int tmp=*upper_bound(v2.begin(),v2.end(),i),tmp1=prea1[i-1]-prea1[las];
					tmp--;
					int tmp2=preb1[tmp]; 
					if (tmp1<=preb1[tmp]-preb1[las]){
						ans+=tmp1;
						preb1[i]=preb1[las]+tmp1;
					}
					else{
						ans+=preb1[tmp]-preb1[las];
						preb1[i]=preb1[tmp];
					}
					if (s1[i]=='1' and tmp1<tmp2-preb1[las]) ans++,preb1[i]++;
					
					tmp1=prea0[i-1]-prea0[las];
					tmp2=preb0[tmp];
					if (tmp1<=preb0[tmp]-preb0[las]){
						ans+=tmp1;
						preb0[i]=preb0[las]+tmp1;
					}
					else{
						ans+=preb0[tmp]-preb0[las];
						preb0[i]=preb0[tmp];
					}
					if (s1[i]=='0' and tmp1<tmp2-preb0[las]) ans++,preb0[i]++;
				}
				else if (s4[i]=='0'){
					int tmp=*upper_bound(v1.begin(),v1.end(),i),tmp1=preb1[i-1]-preb1[las];
					tmp--;
					int tmp2=prea1[tmp];							
					if (tmp1<=prea1[tmp]-prea1[las]){
						ans+=tmp1;
						prea1[i]=prea1[las]+tmp1;
					}
					else{
						ans+=prea1[tmp]-prea1[las];
						prea1[i]=prea1[tmp];
					}
					if (s2[i]=='1' and tmp1<tmp2-prea1[las]) ans++,prea1[i]++;
					
					tmp1=preb0[i-1]-preb0[las];
					tmp2=prea0[tmp];
					if (tmp1<=prea0[tmp]-prea0[las]){
						ans+=tmp1;
						prea0[i]=prea0[las]+tmp1;
					}
					else{
						ans+=prea0[tmp]-prea0[las];
						prea0[i]=prea0[tmp];
					}
					if (s2[i]=='0' and tmp1<tmp2-prea0[las]) ans++,prea0[i]++;
				}
	//			if (s3[i]=='0' or s4[i]=='0') if (ans-tmpp>i-las) ans=tmpp+i-las;
				if (s3[i]=='0' or s4[i]=='0') las=i;
			}
			ans+=min(prea1[n]-prea1[las],preb1[n]-preb1[las])+min(prea0[n]-prea0[las],preb0[n]-preb0[las]);
			cout << ans << endl;
		}
	}

	return 0;
}
