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

const int maxn = 1e5 + 5;

int n, pointer1, pointer2, ans, T, lst1, lst2, spe_c_1, spe_c_2;
int cnt1[5], cnt2[5];
int num1[maxn], num2[maxn];
int sum1[maxn][6], sum2[maxn][6];
bool same_A, same_B, spe_B; 
bool blck1[maxn], blck2[maxn];
char tmpc;

void solve_spe_A(){
	for(int i = 1; i <= n; i++){
		cnt1[num1[i]]++;
		cnt2[num2[i]]++;
	}
	if(cnt1[0] == n){
		ans = cnt2[0];
	}
	else if(cnt2[0] == n){
		ans = cnt1[0];
	}
	else if(cnt1[1] == n){
		ans = cnt2[1];
	}
	else{
		ans = cnt1[1];
	}
	return;
}

void solve_spe_B(){
	for(int i = 1; i <= n; i++){
		if(blck1[i]){
			cnt1[num1[i]]++;
			cnt2[num2[i]]++;
		}
		else{
			ans += min(cnt1[0], cnt2[0]) + min(cnt1[1], cnt2[1]);
			cnt1[0] = cnt1[1] = cnt2[0] = cnt2[1] = 0;
			if(num1[i] == num2[i]){
				ans++;
			}
		}
	}
	ans += min(cnt1[0], cnt2[0]) + min(cnt1[1], cnt2[1]);
	return;
}

void solve_spe_C(){
	for(int i = 1; i <= n; i++){
		if(blck1[i] && blck2[i]){
			cnt1[num1[i]]++;
			cnt2[num2[i]]++;
		}
		else if(blck1[i] == 0){
			cnt2[num2[i]]++;
			ans += min(cnt1[0], cnt2[0]) + min(cnt1[1], cnt2[1]);
			cnt2[0] -= min(cnt1[0], cnt2[0]);
			cnt2[1] -= min(cnt1[1], cnt2[1]);
			cnt1[1] = cnt1[0] = 0;
			if(cnt2[num1[i]]){
				ans++;
				cnt2[num1[i]]--;
			}
		}
		else{
			cnt1[num1[i]]++;
			ans += min(cnt1[0], cnt2[0]) + min(cnt1[1], cnt2[1]);
			cnt1[1] -= min(cnt1[1], cnt2[1]);
			cnt1[0] -= min(cnt1[0], cnt2[0]);
			cnt2[0] = cnt2[1] = 0;
			if(cnt1[num2[i]]){
				ans++;
				cnt1[num2[i]]--;
			}
		}
	}
	cout << ans << endl;
	return;
}

void solve_all(){
	pointer1 = 1, pointer2 = 1, lst1 = 0, lst2 = 0;
	num1[n + 1] = 3;
	num2[n + 1] = 4;
	while(pointer1 <= n || pointer2 <= n){
		while(pointer1 <= n && blck1[pointer1]){
			sum1[pointer1][0] = sum1[pointer1 - 1][0];
			sum1[pointer1][1] = sum1[pointer1 - 1][1];
			sum1[pointer1][num1[pointer1]]++;
			pointer1++;
		}
		while(pointer2 <= n && blck2[pointer2]){
			sum2[pointer2][0] = sum2[pointer2 - 1][0];
			sum2[pointer2][1] = sum2[pointer2 - 1][1];
			sum2[pointer2][num2[pointer2]]++;
			pointer2++; 
		}
		if(pointer1 <= n){
			sum1[pointer1][0] = sum1[pointer1 - 1][0];
			sum1[pointer1][1] = sum1[pointer1 - 1][1];
			sum1[pointer1][num1[pointer1]]++;
		}
		if(pointer2 <= n){
			sum2[pointer2][0] = sum2[pointer2 - 1][0];
			sum2[pointer2][1] = sum2[pointer2 - 1][1];
			sum2[pointer2][num2[pointer2]]++;
		}
//		cout <<" ************* " << pointer1 << " " << pointer2 << endl;
		if(pointer1 > pointer2){
			if(lst1 + 1 == pointer2){
				if(sum1[pointer1 - 1][num2[pointer2]] - sum1[lst1][num2[pointer2]]){
					ans++;
					sum1[pointer1 - 1][num2[pointer2]] --;
					sum1[pointer1][num2[pointer2]]--;
				}
				sum2[pointer2][0] = sum2[pointer2][1] = 0;
				lst2 = pointer2;
				pointer2++;
				continue;
			}
//			cout << "a " << " " << sum1[pointer1 - 1][1] - sum1[lst1][1] << " " << sum2[pointer2][1] - sum2[lst2][1] << endl;
			ans += min(sum1[pointer1 - 1][0] - sum1[lst1][0], sum2[pointer2][0] - sum2[lst2][0]);
			ans += min(sum1[pointer1 - 1][1] - sum1[lst1][0], sum2[pointer2][1] - sum2[lst2][1]);
			sum1[pointer1][0] -= min(sum1[pointer1 - 1][0] - sum1[lst1][0], sum2[pointer2][0] - sum2[lst2][0]);
			sum1[pointer1][1] -= min(sum1[pointer1 - 1][1] - sum1[lst1][0], sum2[pointer2][1] - sum2[lst2][1]);
			sum1[pointer1 - 1][0] -= min(sum1[pointer1 - 1][0] - sum1[lst1][0], sum2[pointer2][0] - sum2[lst2][0]);
			sum1[pointer1 - 1][1] -= min(sum1[pointer1 - 1][1] - sum1[lst1][0], sum2[pointer2][1] - sum2[lst2][1]);
			sum2[pointer2][0] = sum2[pointer2][1] = 0;
			lst2 = pointer2;
			pointer2++;
		}
		else if(pointer2 > pointer1){
			if(lst2 + 1 == pointer1){
				if(sum2[pointer2 - 1][num1[pointer1]] - sum2[lst2][num1[pointer1]]){
					ans++;
					sum2[pointer2 - 1][num1[pointer1]] --;
					sum2[pointer2][num1[pointer1]]--;
				}
				sum1[pointer1][0] = sum1[pointer1][1] = 0;
				lst1 = pointer1;
				pointer1++;
				continue;
			}
			ans += min(sum1[pointer1][0] - sum1[lst1][0], sum2[pointer2 - 1][0] - sum2[lst2][0]);
			ans += min(sum1[pointer1][1] - sum1[lst1][0], sum2[pointer2 - 1][1] - sum2[lst2][1]);
//			cout << ans <<endl;
			sum2[pointer2][0] -= min(sum1[pointer1][0] - sum1[lst1][0], sum2[pointer2 - 1][0] - sum2[lst2][0]);
			sum2[pointer2][1] -= min(sum1[pointer1][1] - sum1[lst1][0], sum2[pointer2 - 1][1] - sum2[lst2][1]);
			sum2[pointer2 - 1][0] -= min(sum1[pointer1][0] - sum1[lst1][0], sum2[pointer2 - 1][0] - sum2[lst2][0]);
			sum2[pointer2 - 1][1] -= min(sum1[pointer1][1] - sum1[lst1][0], sum2[pointer2 - 1][1] - sum2[lst2][1]);
			sum1[pointer1][0] = sum1[pointer1][1] = 0;
			lst1 = pointer1;
			pointer1++;
		}
		else{
			ans += min(sum1[pointer1 - 1][0] - sum1[lst1][0], sum2[pointer2 - 1][0] - sum2[lst2][0]);
			ans += min(sum1[pointer1 - 1][1] - sum1[lst1][0], sum2[pointer2 - 1][1] - sum2[lst2][1]);
			sum1[pointer1][1] = sum2[pointer2][1] = sum1[pointer1][0] = sum2[pointer2][0] = 0;
			if(num1[pointer1] == num2[pointer2]){
				ans++;
			}
			lst2 = pointer2;
			lst1 = pointer1;
			pointer1++, pointer2++;
		}
//		cout << "==========" <<  pointer1 << " " << pointer2 << " " << ans << endl;
	}
	return;
}

void solve(){
	ans = 0;
	spe_c_1 = 0;
	spe_c_2 = 0;
	cnt1[0] = cnt1[1] = cnt2[0] = cnt2[1] = 0;
	same_A = same_B = true;
	spe_B = true;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> tmpc;
		num1[i] = tmpc - '0';
		if(num1[i] != num1[i - 1] && i != 1){
			same_A = false;
		}
	}
	for(int i = 1; i <= n; i++){
		cin >> tmpc;
		num2[i] = tmpc - '0';
		if(num2[i] != num2[i - 1] && i != 1){
			same_B = false;
		}
	}
	for(int i = 1; i <= n; i++){
		cin >> tmpc;
		blck1[i] = tmpc - '0';
		if(!blck1[i]){
			spe_c_1++;
		}
	}
	for(int i = 1; i <= n; i++){
		cin >> tmpc;
		blck2[i] = tmpc - '0';
		if(blck2[i] != blck1[i]){
			spe_B = false;
		}
		if(!blck2[i]){
			spe_c_2++;
		}
	}
	
	if(same_A || same_B){
		solve_spe_A();
	}
	else if(spe_B){
		solve_spe_B();
	}
	else if(spe_c_1 <= 1 && spe_c_2 <= 1){
		solve_spe_C();
	}
	else{
		solve_all();
	}
	cout << ans << endl;
	return;
}

int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin >> T;
	while(T--){
		solve();
	}
	return 0;
}
