#include <bits/stdc++.h>
using namespace std;
const int M=100001;
int T,n;
string x,y;
int s1[M],s2[M];
int t1[M],t2[M];
int ans;
int nxa,nxb,nya,nyb;
void change(int a[],int x,int y){
	int o=a[x];
	a[x]=a[y];
	a[y]=o;
}
void solve(){
	for(int i=1;i<=n;i++){
		if(!t1[i]&&!t2[i]){
			ans++;
			continue;
		}
		else if(!t1[i]){
			for(int j=i;j<=n;j++){
				if(!t2[j])break;
				if(s2[j]==s1[i]){
					change(s2,i,j);
					ans++;
					break;
				}
			}
		}
		else if(!t2[i]){
			for(int j=i;j<=n;j++){
				if(!t1[j])break;
				if(s1[j]==s2[i]){
					change(s1,i,j);
					ans++;
					break;
				}
			}
		}
		else{
			int p=0,q=0;
			for(int j=i;i<=n;j++){
				if(p&&q){
					ans+=max(nxb,nya)+max(nxa,nyb);
					nxb=0;nxa=0;nyb=0;nya=0;
					break;
				}
				if(!t1[j]) p=1;
				if(!t2[j]) q=1;
				if(!p){
					if(s1[j]==1)nxb++;
					else if(s1[j]==0) nxa++;
				}
				if(!q){
					if(s2[j]==1) nya++;
					else if(s2[j]==0) nyb++;
				}
			}
		}
	}
}
int main()
{
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>T;
	while(T--){
		ans=0;
		cin>>n>>x>>y;
		for(int i=1;i<=n;i++){
			s1[i]=x[i-1]-'0';
			s2[i]=y[i-1]-'0';
		}
		cin>>x>>y;
		for(int i=1;i<=n;i++){
			t1[i]=x[i-1]-'0';
			t2[i]=y[i-1]-'0';
		}
		if(n<=10){
			nxb=0;nxa=0;nyb=0;nya=0;
			solve();
		}
		else{
			for(int i=1;i<=n;i++)
				if(s1[i]==s2[i]) ans++;
			cout<<ans<<endl;
		}
		
	}
	return 0;
}
