#include <bits/stdc++.h>
using namespace std;
int tt,n,ans;
char a[100010],b[100010],ta[100010],tb[100010];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin>>tt;
	while(tt--){ans=0;
		scanf("%d%s%s%s%s",&n,a+1,b+1,ta+1,tb+1);
		int la=1,lb=1,ra=0,rb=0,ca=0,cb=0,da=0,db=0;
		while(la<=n&&lb<=n){
			if(la>ra){
				ca=da=0;
				while(ra<n&&ta[ra+1]-'0') ++ra,ca+=(a[ra]-'0'),da+=('1'-a[ra]);
				if(ra<la){
					++ra,ca+=(a[ra]-'0'),da+=('1'-a[ra]);
				}
			}
			if(lb>rb){
				cb=db=0;
				while(rb<n&&tb[rb+1]-'0') ++rb,cb+=(b[rb]-'0'),db+=('1'-b[rb]);
				if(rb<lb){
					++rb,cb+=(b[rb]-'0'),db+=('1'-b[rb]);
				}
			}
			if(ra>rb){
				ans+=min(ca,cb)+min(da,db);
				if(ca<cb) da-=cb-ca,ca=0;
				else ca-=cb;
				if(da<db) ca-=db-da,da=0;
				else da-=db;
				lb=rb+1;
			}else{
				ans+=min(ca,cb)+min(da,db);
				if(cb<ca) db-=ca-cb,cb=0;
				else cb-=ca;
				if(db<da) cb-=da-db,db=0;
				else db-=da;
				la=ra+1;
			}
			//cout<<la<<' '<<lb<<' '<<ans<<endl;
		}
		printf("%d\n",ans);
	}
	return 0;
}

