#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int n;
int ans;
int main(){
	//freopen("edit.in","r",stdin);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	scanf("%d",&T);
	while(T--){
		string a,b;
		string s1,s2;
		scanf("%d",&n);
		ans = 0;
		int ra = 0,rb=0;
		cin>>a>>b>>s1>>s2;
		//cout<<a<<endl<<b<<endl; 
		for(int i = 0;i<n;++i){
			//cout<<i<<":"<<ans<<endl;
			if(a[i]==b[i]){
				++ans;
				continue;
			}
			ra = max(i+1,ra);
			rb = max(i+1,rb);
			while(s1[i]=='1'&&ra<n&&s1[ra]=='1'&&a[ra]==a[i]){
				++ra;
			}
			if(ra<n&&s1[i]=='1'&&s1[ra]=='1'&&a[ra]!=a[i]){
				swap(a[ra],a[i]);
				++ans;
				continue;
			}
			while(s2[i]=='1'&&rb<n&&s2[rb]=='1'&&b[rb]==b[i]){
				++rb;
			}
			if(rb<n&&s2[i]=='1'&&s2[rb]=='1'&&b[rb]!=b[i]){
				swap(b[rb],b[i]);
				++ans;
			}
		}
		//cout<<a<<endl<<b<<endl;
		printf("%d\n",ans);
	}
	return 0;
}
