#include<bits/stdc++.h>
using namespace std;
int t,n,suma[100005],sumb[100005],ans,cnta,cntb,tmpa,tmpb,i,j;
char sa[100005],sb[100005],sa2[100005],sb2[100005];
struct qwe{
	int l,r;
}a[100005],b[100005];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> t;
	while(t--){
		cin >> n;
		cin >> sa+1 >> sb+1 >> sa2+1 >> sb2+1;
		ans = cnta = cntb = tmpa = tmpb = 0;
		for(i=1;i<=n+1;i++){
			if(sa2[i]=='1') tmpa++;
			else{
				if(tmpa>1) a[++cnta] = {i-tmpa,i-1};
				tmpa = 0;
			}
			if(sb2[i]=='1') tmpb++;
			else{
				if(tmpb>1) b[++cntb] = {i-tmpb,i-1};
				tmpb = 0;
			}
			suma[i] = sa[i]-'0' + suma[i-1];
			sumb[i] = sb[i]-'0' + sumb[i-1];
		}
		int i=1,j=1;
		while(i<=cnta||j<=cntb){
			if(j>cntb||a[i].l<b[j].l&&i<=cnta) {
				int tmp = suma[a[i].r] - suma[a[i].l-1];
				for(int k=a[i].l;k<=a[i].r;k++){
					if(sb[k]=='1'){
						if(tmp>0) tmp--,sa[k]='1';
						else sa[k]='0';
					}else{
						if(a[i].r-k+1-tmp>0) sa[k]='0';
						else tmp--,sa[k]='1';
					}
				}
				i++;
			}else{
				int tmp = sumb[b[j].r] - sumb[b[j].l-1];
				for(int k=b[j].l;k<=b[j].r;k++){
					if(sa[k]=='1'){
						if(tmp>0) tmp--,sb[k]='1';
						else sb[k]='0';
					}else{
						if(b[j].r-k+1-tmp>0) sb[k]='0';
						else tmp--,sb[k]='1';
					}
				}
				j++;
			}
		}
		for(int i=1;i<=n;i++)
			if(sa[i]==sb[i]) ans++;
		cout << ans << "\n";
	}
	return 0;
} 
