#include<bits/stdc++.h>
using namespace std;
int maxcom(int left,int right,string s1,string s2){
	int o1=0,o2=0,z1=0,z2=0;
	for(int i=left;i<=right;i++){
		if(s1[i]=='1')	o1++;
		else	z1++;
		if(s2[i]=='1')	o2++;
		else z2++;
	}
//	printf("left: %d right:%d res:%d \n",left,right,min(z1,z2)+min(o1,o2));
//	cout<<z1<<' '<<z2<<' '<<o1<<' '<<o2<<endl;
	return min(z1,z2)+min(o1,o2);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		string s1,s2,t1,t2;
		char c;
		for(int i=0;i<n;i++){
			cin>>c;
			s1.push_back(c);
		}
		for(int i=0;i<n;i++){
			cin>>c;
			s2.push_back(c);
		}
		for(int i=0;i<n;i++){
			cin>>c;
			t1.push_back(c);
		}
		for(int i=0;i<n;i++){
			cin>>c;
			t2.push_back(c);
		}
		int ans=0;
		t1.push_back('0');
		t2.push_back('0');
		int idx=0,left=-1,lin=1;
			
		bool flag=false;
		while(idx<n){
			if(t1[idx]=='0' && t2[idx]=='0'){
				if(s1[idx]==s2[idx])	ans++;
				idx++;
				continue;
			}
			if(lin==1 && t1[idx+1]=='0'){
				if(flag){
					ans+=maxcom(left,idx,s1,s2);
					left=-1;
					idx++;
					flag=false;
					continue;
				}
				lin=2;
				flag=true;
			}
			else if(lin==2 && t2[idx+1]=='0'){
				if(flag){
					ans+=maxcom(left,idx,s1,s2);
					left=-1;
					idx++;
					flag=false;
					continue;
				}
				lin=1;
				flag=true;
			}
			if(left==-1)	left=idx;
			if(t1[idx+1]=='0'&&t2[idx]=='0'){
				ans+=maxcom(left,idx,s1,s2);
				left=-1;
				idx++;
				flag=false;
				continue;
			}
			if(t2[idx+1]=='0' &&t1[idx]=='0'){
				ans+=maxcom(left,idx,s1,s2);
				left=-1;
				idx++;
				flag=false;
				continue;
			}
			if(t2[idx+1]=='0' && t1[idx+1]=='0'){
				ans+=maxcom(left,idx,s1,s2);
				left=-1;
				idx++;
				flag=false;
				continue;
			}
			idx++;
		}
		printf("%d\n",ans);
	}
	return 0;
} 
