#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int n;
int T;
const int N = 1000100;
char s1[N];
char s2[N];
char c1[N];
char c2[N];
bool have0,have1;
//考虑贪心
//如果当前字符串不能匹配且可以交换那么就把他交换（找与之不同的相互交换）
//理由如下 如果当前字符与前一个不相同  交换一下两者的都能匹配上
//如果两者相同  交换一下不影响贡献
//如果出现不能交换的  以为着他出现了断点
//对两个串都执行贪心操作  2*n
void solve1() { //满足性质A
	long long int cnt = 0;
	for(int i = 0; i<n; i++) {
		if(s1[i]==s2[i]) {
			cnt++;
		}
	}

	printf("%d\n",cnt);
}
void solve2() {
	long long int cnt = 0;
	for(int k = 1; k<=100; k++) {
		for(int i = 0; i<n; i++) {
			if(s1[i]!=s2[i]&&c1[i]=='1') { //如果当前不匹配且当前字符可以交换
				if(s1[i]!=s1[i+1]&&c1[i+1]=='1') {
					swap(s1[i],s1[i+1]);
				}
			}
		}
		for(int i = n; i>=0; i--) {
			if(s1[i]!=s2[i]&&c2[i]=='1') {
				if(s2[i]!=s2[i-1]&&c2[i-1]=='0') {
					swap(s2[i],s2[i-1]);
				}
			}
		}
	}
	for(int i = 0; i<n; i++) {
			if(s1[i]==s2[i]) {
				cnt++;
			}
		}
	printf("%d\n",cnt);
}
void solve3()
{ 
	int cnt = 0;
	int s11 = 0;
	int s21 = 0;
	int s12 = 0;
	int s22 = 0;
	for(int i=0;i<n;i++)
	{
		if(c1[i]=='1')//可以动 
		{
			if(s1[i]=='1') s11++;
			else s12++;
			if(s2[i]=='1') s21++;
			else s22++; 
		}		
		else
		{
			if(s1[i]==s2[i]) cnt++;
			cnt = cnt+min(s11,s21)+min(s22,s12);
			s11 = 0;
			s12 = 0;
			s21 = 0;
			s22 = 0;
		}
	}
	
	printf("%d\n",cnt);
}
int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	scanf("%d",&T);
	while(T--) {
		scanf("%d",&n);
		scanf("%s",s1);
		scanf("%s",s2);
		scanf("%s",c1);
		scanf("%s",c2);
		for(int i=0; i<n; i++) {
			if(s1[i]=='0') have0 = true;
			else have1 = true;
		}
		bool flag = true;
		for(int i = 0;i<n;i++)
		{
			if(c1[i]==c2[i]) continue;
			else flag = false;
		}
		if(have1&&have0==false) solve1();
		else if(flag) solve3();
		else solve2();
	}
}
