#include<bits/stdc++.h> 
using namespace std;
const int N=1e5+10;
char s1[N],s2[N],t1[N],t2[N];
bool flag1[2000],flag2[2000];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t,n;
	scanf("%d",&t);
	while (t--){
		int cnt1=0,cnt2; 
		scanf("%d%s%s%s%s",&n,s1+1,s2+1,t1+1,t2+1);
		if (n<=10){
			int maxn=1;
			memset(flag1,0,sizeof(flag1));
			for (int i=1;i<=n;i++) maxn*=2;
			/*for (int i=n;i>=1;i--)
				if (t1[i]=='0'){
					for (int i=0;i<maxn;i++)
				}
			continue;*/
		}
		for (int i=1;i<=n;i++) cnt1+=s1[i]-'0';
		if (cnt1==n){
			cnt2=0;
			for (int i=1;i<=n;i++) cnt2+=s2[i]-'0';
			printf("%d\n",cnt2);
			continue;
		}
		if (cnt1==0){
			cnt2=0;
			for (int i=1;i<=n;i++) cnt2+=(s2[i]-'0')^1;
			printf("%d\n",cnt2);
			continue;
		}
		if (strcmp(t1+1,t2+1)==0){
			int ans=0,i=1,j=0;
			cnt1=cnt2=0;
			while (i<=n){
				while (t1[i]=='1'&&i<=n) cnt1+=s1[i]-'0',cnt2+=s2[i]-'0',i++;
				if (cnt1<cnt2) swap(cnt1,cnt2);
				ans+=(i-j-1)-(cnt1-cnt2);
				if (i<=n){
					j=i;i++;
					if (s1[j]==s2[j]) ans++;
					cnt1=cnt2=0;
				}
			}
			printf("%d\n",ans);	
			continue;
		}
	}
	return 0;
}
