#include<iostream>
#include<string>
#include<cstdio>
#define int long long
#define endl "\n"
using namespace std;
const int N=1e5+5;
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		string a,b,s,t;
		cin>>a>>b>>s>>t;a=" "+a,b=" "+b,s=" "+s,t=" "+t;
		int p=1,q=1,ans=0;
		while(p<=n || q<=n){
			if(s[p]=='0' && t[q]=='0'){
				ans+=(a[p]==b[q]);
				p++,q++;
				continue;
			}
			int x=p,y=q;
			while(x<=n && s[x]=='1')x++;x--;
			while(y<=n && t[y]=='1')y++;y--;
			if(x>=y){
				int l=p,r=x;
				int cou0=0,cou1=0;
				for(int i=l;i<=r;i++){
					if(a[i]=='0')cou0++;
					else cou1++;
				}
				if(t[r+1]=='1'){
					while(t[r]=='1')r--;
				}
				for(int i=l;i<=r;i++){
					if(b[i]=='0' && cou0)cou0--,ans++;
					if(b[i]=='1' && cou1)cou1--,ans++;
				}
				for(int i=r+1;i<=x;i++){
					if(cou0)cou0--,a[i]='0';
					else cou1--,a[i]='1';
				}
				p=q=r+1;
			}
			else{
				int l=q,r=y;
				int cou0=0,cou1=0;
				for(int i=l;i<=r;i++){
					if(b[i]=='0')cou0++;
					else cou1++;
				}
				if(s[r+1]=='1'){
					while(s[r]=='1')r--;
				}
				for(int i=l;i<=r;i++){
					if(a[i]=='0' && cou0)cou0--,ans++;
					if(a[i]=='1' && cou1)cou1--,ans++;
				}
				for(int i=r+1;i<=y;i++){
					if(cou0)cou0--,b[i]='0';
					else cou1--,b[i]='1';
				}
				p=q=r+1;
			}
		}
		cout<<ans<<endl;
	}
}
