#include<bits/stdc++.h>

using namespace std;

const int maxn = 1e5+10;
int s1[maxn], s2[maxn];
int t1[maxn], t2[maxn];

//int vis[40]; // only for dfs
//int cur1[40], cur2[40];
//int solve0(int n){
//	
//}

int solve1(int n){
//	cout<<"solving 1";
	int key = s1[1];
	int cnt=0;
	for(int i=1;i<=n;i++){
		if(s2[i] == key) cnt++;
	}
	return cnt;
}

int solve2(int n){
//	cout<<"solving2...\n";
	int cnt=0;
	int l=1,r=1;
	for(int i=1;i<=n;i++){
		if(t1[i]==0){
			int s11=0, s10=0;
			int s21=0, s20=0;
			for(int j=l;j<=r;j++){
				if(s1[j] == 1) s11++;
				else s10++;
				
				if(s2[j] == 1) s21++;
				else s20++;
			}
//			cout<<"range; "<<l<<" "<<r<<" with:"<<s11<<s10<<" "<<s21<<s20<<endl;
			cnt += min(s11, s21) + min(s10, s20);
			if(s1[i] == s2[i]) cnt++;
			
			l = i+1;
			// calculate
		}else{
			r = i;
		}
	}
	
	int s11=0, s10=0;
	int s21=0, s20=0;
	for(int j=l;j<=r;j++){
		if(s1[j] == 1) s11++;
		else s10++;
		
		if(s2[j] == 1) s21++;
		else s20++;
	}

	cnt += min(s11, s21) + min(s10, s20);

	return cnt;
}

int solve3(int n){
	int id1=0, id2=0;
	for(int i=1;i<=n;i++){
		if(s1[i]==0) {
			id1=i;
			break;
		}
	}
	for(int i=1;i<=n;i++){
		if(s2[i]==0){
			id2 = i;
			break;
		}
	}
	if (id1 == id2) return n;
	else if(id1 < id2){
		while(id1 < id2 && t1[id1]==1){
			id1++;
		}
		if(id1 == id2) return n;
		while(id1 < id2 && t2[id2]==1){
			id2--;
		}
		if(id1 == id2) return n;
		else return n-2;
	}else{
		while(id1 > id2 && t1[id1] == 1){
			id1 --;
		}
		if(id1 == id2) return n;
		while(id2 < id1 && t2[id2] == 1){
			id2++;
		}
		if(id1 == id2) return n;
		else return n-2;
	}
	
}
//
//int solve(int n){
//}

int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	int T;
	cin>>T;
	while(T--){
		int n;
		cin>>n;
		
		bool flaga = true;
		bool flagb = true;
		bool flagc = true;
		int zero1=0, zero2=0;
		
		string string1,string2;
		cin>>string1;
		cin>>string2;
		
		for(int i=n;i>=1;i--){
			s1[i] = (string1[i-1] - '0') ;
//			string1 /= 10;
			
			if(s1[i]==0) zero1++;
			
			if(flaga && i<n && s1[i] != s1[i+1]){
				flaga = false;
//				cout<<s1[i]<<" "<<s1[i+1]<<endl;
			}
		}
		for(int i=n;i>=1;i--){
			s2[i] = string2[i-1] - '0';
//			string2 /= 10;
			if(s2[i] == 0) zero2++;
		}
		if (zero1==1 && zero2 == 1) flagc = true;
		else flagc = false;
		
//		cout<<zero1<<"-"<<zero2<<endl;
		string ts1, ts2;
		cin>>ts1>>ts2;
		
		for(int i=n;i>=1;i--){
//			cin>>t1[i];
			t1[i] = ts1[i-1]-'0';
//			ts1 /= 10;
		}
		
		for(int i=n;i>=1;i--){
//			cin>>t2[i];
			t2[i] = ts2[i-1] - '0';
//			ts2 /= 10;
			
			if(t2[i] != t1[i]){
				flagb = false;
			}
		}
//		for(int i=1;i<=n;i++) cout<<t1[i]<<" "<<t2[i]<<endl;
		int result=0;
		
		if(flaga) result=solve1(n);
		else if(flagb) result=solve2(n);
		else if(flagc) result = solve3(n);
//		else result=solve(n);
		
		cout<<result<<endl;
	}
	
}
