#include <iostream> 
#include <stdio.h>
#include <string> 
#include <unordered_map>
#include <queue>
using namespace std;

string sa,sb,ta,tb;
int T,n;

int main(){
	
	freopen("edit.in","r",stdin);
	freopen("ans.out","w",stdout);
	cin >>T;
	while(T--){
		int ans=0;
		int ls=0;
		int lst=0; 
		int flag=0;
		unordered_map<string,int> cura;
		unordered_map<string,int> curb;
		queue<unordered_map<string,int>> lasta;
		queue<unordered_map<string,int>> lastb;
		unordered_map<string,int> zero;

		zero["48"]=0;
		zero["49"]=0;
		lasta.push(zero);
		lastb.push(zero);
		
		cin >>n>>sa>>sb>>ta>>tb;
	
			
		for(int i=0;i<n;i++){			
		cura[to_string(sa[i])]++;
		curb[to_string(sb[i])]++;
		if(tb[i]=='0'||ta[i]=='0'){
			
			lasta.push(cura);
			lastb.push(curb);
			unordered_map<string ,int>lamp=lasta.front();
			unordered_map<string ,int>lbmp=lastb.front();
			lasta.pop();
			lastb.pop();	
			
			int alastwoz=cura["48"]+lamp["48"];
			int alastwoo=cura["49"]+lamp["49"];
			int blastwoz=curb["48"]+lbmp["48"];
			int blastwoo=curb["49"]+lbmp["49"];
			
			int tmpa=lst+min(alastwoo,blastwoo)+min(alastwoz,blastwoz);
			int tmpb=ls+min(lamp["48"],lbmp["48"])+min(lamp["49"],lbmp["49"]);
			ans=max(tmpa,tmpb);
			lst=ls;
			ls=ans;
			
			cura["48"]=0;
			cura["49"]=0;
			curb["48"]=0;
			curb["49"]=0;				
	

		}

	}
	cout <<ans<< endl; 
		

	}
	
	return 0;
}


