#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int N=5e5+10;
int a[N];
int cnt1[N],cnt2[N],fa[N];
bitset<N>lim;
int n,ans,t;
int fd(int x){
	if(fa[x]!=x)fa[x]=fd(fa[x]);
	return fa[x];
}
inline void add(int x,int y){
//	cerr<<"add:"<<x<<" "<<y<<endl;
	int fx=fd(x),fy=fd(y);
	if(fx==fy)return ;
	fa[fx]=fy;
	cnt1[fy]+=cnt1[fx];
	cnt2[fy]+=cnt2[fx];
}
inline int read(){
	int res=0;bool s=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')s=1;
	for(;isdigit(c);c=getchar())res=(res<<3)+(res<<1)+(c^48);
	return s?-res:res;
}
inline int gb(){
	char c=getchar();
	while(!isdigit(c))c=getchar();
	return (c^48);
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	t=read();
	while(t--){
		n=read();
		ans=0;
		for(int i=1;i<=2*n;i++)a[i]=gb();
		for(int i=1;i<=2*n;i++)lim[i]=gb();
		for(int i=1;i<=2*n;i++)fa[i]=i;
		for(int i=1;i<=n;i++){
			if(a[i]==1)cnt1[i]=1,cnt2[i]=0;
			else cnt2[i]=1,cnt1[i]=0;
			if(i-1&&lim[i-1]&&lim[i]){
				add(i,i-1);
			}
		}
		for(int i=n+1;i<=2*n;i++){
			if(a[i]==1)cnt1[i]=1,cnt2[i]=0;
			else cnt2[i]=1,cnt1[i]=0;
//			if(lim[i])putchar('1');
//			else putchar('0');
			if((i-1!=n)&&lim[i-1]&&lim[i]){
				add(i,i-1);
			}
		}
		for(int i=1;i<=n;i++){
//			cerr<<fd(i)<<" "<<fd(i+n)-n<<endl;
//			cerr<<cnt1[fd(i)]<<" "<<cnt1[fd(i+n)]<<endl;
//			cerr<<cnt2[fd(i)]<<" "<<cnt2[fd(i+n)]<<endl;
			if(cnt1[fd(i)]&&cnt1[fd(i+n)]){
//				cerr<<"#1:"<<i<<endl;
				cnt1[fd(i)]--;cnt1[fd(i+n)]--;
				ans++;
			}
			else if(cnt2[fd(i)]&&cnt2[fd(i+n)]){
//				cerr<<"#2:"<<i<<endl;
				cnt2[fd(i)]--;cnt2[fd(i+n)]--;
				ans++;
			}
			else {
				if(cnt1[fd(i)])cnt1[fd(i)]--;
				if(cnt2[fd(i)])cnt2[fd(i)]--;
				if(cnt1[fd(n+i)])cnt1[fd(n+i)]--;
				if(cnt2[fd(n+i)])cnt2[fd(n+i)]--;
			}
		}
		printf("%lld\n",ans);		
	}

	return 0;
}
