#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int t,n;
string s1,s2;
string t1,t2;
int t1a,t1b,t2a,t2b;//0 a 1b
bool vis1[N],vis2[N];
//int nexz[N];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >>t;
	while(t--){
		bool flagA1=0,flagA2=0;
		int flagc1=0,flagc2=0;
		int cnt=0;
		t1a=t1b=t2a=t2b=0;
		cin >>n;
		for(int i=0;i<n;i++)vis1[i]=vis2[i]=0;
		cin >> s1>>s2>>t1>>t2;
		for(int i=0;i<n;i++){
			if(s1[i]=='1')flagA1=1;
			else flagA2=1;
			if(s1[i]=='0')flagc1++;
			if(s2[i]=='0')flagc2++;
		}
		if(!flagA1 || !flagA2){
			for(int i=0;i<n;i++){
				if(s2[i]==s1[i])cnt++;
			}
			cout<<cnt<<"\n";
			continue;
		}
		int p1=0,p2=0,p3=0;
		if(t1==t2){
			for(int i=0;i<n;i++){
				if(t1[i]=='0'){
					if(s1[i]==s2[i])cnt++;
					cnt+=min(t1a,t2a)+min(t2b,t1b);
					t1a=t1b=t2a=t2b=0;
				}else {
					if(s1[i]=='1')t1b++;else t1a++;
					if(s2[i]=='1')t2b++;else t2a++;
				}
				
			}
			cnt+=min(t1a,t2a)+min(t2b,t1b);
			cout<<cnt<<"\n";
			continue;
		
		}
		if(flagc1==1 && flagc2==1){
			
			continue;
		}

		}
		//cout<<cnt<<"\n";
		
	return 0;
}
