#include<bits/stdc++.h>
#define rg register 
#define step inline void
typedef unsigned long long ull;
typedef long long ll;
const int maxi=+9;
using namespace std;
int T,N,w1,b1,w2,b2,ans;
string s1,s2,t1,t2;
inline int read(){
	rg int x=0;rg char c=getchar();
	for(;!isdigit(c);c=getchar());
	for(;isdigit(c);x=(x<<3)+(x<<1)+(c^48),c=getchar());
	return x;
}
inline int min(int a,int b){return a<b?a:b;} 
namespace B{
	step solve(){
		
	}
}
//我服了又一次读错题了，发现的时候相似的心都有了，接下来准备其他题罢 
namespace T1{
	step clear(){
		ans=w1=b1=w2=b2=0; 
	}
	step getin(){
		N=read();
		cin>>s1>>s2>>t1>>t2;
	}
	step statistics(){
		for(rg int i=0,j=0,l1=0,l2=0;i<N||j<N;){
			for(;t1[i]!='0'&&i<N;i++){
				s1[i]=='1'?b1++:w1++;
				l1++;
			}
			for(;t2[j]!='0'&&j<N;j++){
				s2[j]=='1'?b2++:w2++;
				l2++;
			}
			for(;l1&&l2;l1--,l2--){
				if(b1&&b2){
					ans++,b1--,b2--;
				}
				if(w1&&w2){
					ans++,w1--,w2--;
				}
			}
			
			if(i<j){
				if(s1[i]=='1'){
					if(b2)ans++,b2--;
				}else{
					if(w2)ans++,w2--;
				}
				i++,l2--,w1=b1=0;
			}else if(j<i){
				if(s2[j]=='1'){
					if(b1)ans++,b1--;
				}else{
					if(w1)ans++,w1--;
				}
				j++,l1--,w2=b2=0;
			}else if(i<N&&j<N){
				ans+=(s1[i]==s2[j]);
				i++,j++;w1=w2=b1=b2=0;
			}
		}
	}
	step output(){
		printf("%d\n",ans);
	}
	step solve(){
		clear();
		getin();
//		if(s1==s2){
//			B::solve();return;
//		}
		statistics();
		output();
	}
	step init(){
		T=read();
		for(;T--;)solve();
	}
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	T1::init();
	return 0;
}
