#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define PII pair<int , int> 
#define lowbit(x) (x & -x)

bool ST;
const int N = 1e5 + 10;
int n , T;
char s1[N] , s2[N] , t1[N] , t2[N];
int cnt1 = 0 , cnt2 = 0;
struct Node{
	ll l , r , num;
	bool operator < (const Node &a) const {
		return r < a.r;
	}
}e1[N] , e2[N];

int read(){
	int sum = 0;
	bool flag = true;
	char c = getchar();
	for(;!isdigit(c);c = getchar())if(c == '-')flag ^= true;
	for(;isdigit(c);c = getchar())sum = (sum << 1) + (sum << 3) + (c ^ 48);
	return flag ? sum : -sum;
}
void out_write(int x){if(x > 9)out_write(x / 10);putchar(x % 10 + '0');}
void write(int x){if(x < 0){putchar('-');out_write(-x);}else out_write(x);}
void work(){
	scanf("%d" , &n);
	scanf("%s" , s1 + 1);scanf("%s" , s2 + 1);scanf("%s" , t1 + 1);scanf("%s" , t2 + 1);
	cnt1 = cnt2 = 0;
	for(int i = 1;i <= n;++ i){
		if(t1[i] == '0'){e1[++ cnt1].l = i;e1[cnt1].r = i;e1[cnt1].num = (s1[i] == '1');}
		else {
			e1[++ cnt1].l = i;
			int sum = 0;
			int j = i;
			while(j <= n && t1[j] == '1'){
				if(s1[j] == '1')sum ++;
				++ j;
			}
			-- j;
			e1[cnt1].r = j;i = j;e1[cnt1].num = sum;
		}
	}
	for(int i = 1;i <= n;++ i){
		if(t2[i] == '0'){e2[++ cnt2].l = i;e2[cnt2].r = i;e2[cnt2].num = (s2[i] == '1');}
		else {
			e2[++ cnt2].l = i;
			int sum = 0;
			int j = i;
			while(j <= n && t2[j] == '1'){
				if(s2[j] == '1')sum ++;
				++ j;
			}
			-- j;
			e2[cnt2].r = j;i = j;e2[cnt2].num = sum;
		}
	}
//	for(int i = 1;i <= cnt1;++ i){
//		cerr << e1[i].l << " " << e1[i].r << " " << e1[i].num << endl;
//	}
//	cerr << endl;
//	for(int i = 1;i <= cnt2;++ i){
//		cerr << e2[i].l << " " << e2[i].r << " " << e2[i].num << endl;
//	}
//	cerr << endl;
	int j = 1 , k = 1;
	int ans = 0;
	for(int i = 1;i <= n;++ i){
		while(e1[j].l > e1[j].r)++ j;
		while(e2[k].l > e2[k].r)++ k;
		if(e1[j].r == i){
			int sum1 = e1[j].num;
			int sum2 = e2[k].num;
			int sum3 = e1[j].r - e1[j].l + 1 - sum1;
			int sum4 = e2[k].r - e2[k].l + 1 - sum2;
			
//			cerr << e1[j].l << " " << e1[j].r << " " << sum1 << " " << sum3 << endl;
//			cerr << e2[k].l << " " << e2[k].r << " " << sum2 << " " << sum4 << endl;
//			cerr << e1[j].l << " " << e1[j].r << " " << min(sum1 , sum2) + min(sum3 , sum4) << endl;
			ans += min(sum1 , sum2) + min(sum3 , sum4);
			e2[k].l = i + 1;e2[k].num = e2[k].num - min(sum1 , sum2) - (sum3 > sum4 ? sum3 - sum4 : 0);
//			cerr << e2[k].l << " " << e2[k].r << " " << e2[k].num << endl;
			++ j;
		}
		else if(e2[k].r == i){
			int sum1 = e2[k].num;
			int sum2 = e1[j].num;
			int sum3 = e2[k].r - e2[k].l + 1 - sum1;
			int sum4 = e1[j].r - e1[j].l + 1 - sum2;
//			cerr << sum1 << " " << sum2 << " " << sum3 << " " << sum4 << endl;
//			cerr << e1[j].l << " " << e1[j].r << " " << sum2 << " " << sum4 << endl;
//			cerr << e2[k].l << " " << e2[k].r << " " << sum1 << " " << sum3 << endl;
//			cerr << e2[k].l << " " << e2[k].r << " " << min(sum1 , sum2) + min(sum3 , sum4) << endl;
			ans += min(sum1 , sum2) + min(sum3 , sum4);
			e1[j].l = i + 1;e1[j].num = e1[j].num - min(sum1 , sum2) - (sum3 > sum4 ? sum3 - sum4 : 0);
//			cerr << e1[j].l << " " << e1[j].r << " " << e1[j].num << endl;
			++ k;
		}
	}
	write(ans);putchar('\n');
}
bool ED;

int main(){
	freopen("edit.in" , "r" , stdin);
	freopen("edit.out" , "w" , stdout);
//	cerr << ((&ST) - (&ED)) / 1024.0 / 1024.0 << endl;
//	double st = clock();
	scanf("%d" , &T);
	while(T --){work();}
//	double ed = clock();
//	cerr << (ed - st) / CLOCKS_PER_SEC << endl;
	return 0;
}
/*
1
6
011101
111010
111010
101101

*/
