#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int T,n,a[2][N],b[2][N],s[2][N][2],cnta1,cnta2;
vector <pair<int,int> > v[2];
bool check1(){
	for(int i = 2; i <= n; i++) if(a[0][i] != a[0][i - 1]) return false;
	return true;
}
bool check2(){
	for(int i = 1; i <= n; i++) if(b[0][i] != b[1][i]) return false;
	return true;
}
void subtask2(){
	int f = a[0][1],ans = 0;
	for(int i = 1; i <= n; i++) if(a[1][i] == f) ans++;
	cout << ans << '\n';
	return;
}
void subtask3(){
	int cnta0 = 0,cnta1 = 0,cntb0 = 0,cntb1 = 0,ans = 0;
	for(int i = 1; i <= n + 1; i++){
		if(b[0][i] == 0){
			ans += min(cnta0,cntb0) + min(cnta1,cntb1);
			if(a[0][i] == a[1][i] && i != n + 1) ans++;
			cnta0 = cntb0 = cnta1 = cntb1 = 0; 
		}
		else{
			if(a[0][i] == 0) cnta0++;
			else cnta1++;
			if(a[1][i] == 0) cntb0++;
			else cntb1++;
		}
	}
	cout << ans << '\n';
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	cin >> T;
	while(T--){
		cin >> n;
		cnta1 = cnta2 = 0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		for(int i = 1; i <= n; i++){
			char c;
			cin >> c;
			a[0][i] = c - '0';
			s[0][i][a[0][i]] = s[0][i - 1][a[0][i]] + 1;
			s[0][i][!a[0][i]] = s[0][i - 1][!a[0][i]];
		}
		for(int i = 1; i <= n; i++){
			char c;
			cin >> c;
			a[1][i] = c - '0';
			s[1][i][a[0][i]] = s[1][i - 1][a[0][i]] + 1;
			s[1][i][!a[0][i]] = s[1][i - 1][!a[0][i]];
		}
		for(int i = 1; i <= n; i++){
			char c;
			cin >> c;
			b[0][i] = c - '0';
		}
		for(int i = 1; i <= n; i++){
			char c;
			cin >> c;
			b[1][i] = c - '0';
		}
		if(check1()) subtask2();
		else if(check2()) subtask3();
	}
	return 0;
}
