#include<bits/stdc++.h>
using namespace std;
int T,n;
char sa[100010],sb[100010];
char ta[100010],tb[100010];
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%s%s%s%s",&n,sa+1,sb+1,ta+1,tb+1);
		int ca=0,za=0,cb=0,zb=0,pa=0,pb=0,ans=0;
		while(pa<=n&&pb<=n){
			while(pa<n&&ta[pa+1]!='0'){
				pa++;
				if(sa[pa]=='0')za++;
				else ca++;
			}
			while(pb<n&&tb[pb+1]!='0'){
				pb++;
				if(sb[pb]=='0')zb++;
				else cb++;
			}
			if(pa>pb){
				pb++;
				if(sb[pb]=='0')zb++;
				else cb++;
				if(ca>=cb)ans+=cb,ca-=cb,cb=0;
				else ans+=ca,za+=ca-cb,ca=cb=0;
				if(za>=zb)ans+=zb,za-=zb,zb=0;
				else ans+=za,ca+=za-zb,za=zb=0;
			}
			else if(pa<pb){
				pa++;
				if(sa[pa]=='0')za++;
				else ca++;
				if(cb>=ca)ans+=ca,cb-=ca,ca=0;
				else ans+=cb,zb+=cb-ca,cb=ca=0;
				if(zb>=za)ans+=za,zb-=za,za=0;
				else ans+=zb,cb+=zb-za,zb=za=0;
			}
			else{
				ans+=min(ca,cb)+min(za,zb);
				if(pa!=n)ans+=(sa[pa+1]==sb[pb+1]);
				za=zb=ca=cb=0,pa++,pb++;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}
