#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

int n;
int a[N],b[N];
int c[N],d[N];
string sss;
int tota,totb;
int mpa[N],mpb[N];
int fan_huia[N],fan_huib[N];
pair<int,int> blocka[N],blockb[N];
void solve(){
	cin >> n;tota = totb = 0;
	cin >> sss;for (int i = 1;i <= n;i++) a[i] = sss[i - 1] - '0',blocka[i] = {0,0},mpa[i] = fan_huia[i] = 0;
	cin >> sss;for (int i = 1;i <= n;i++) b[i] = sss[i - 1] - '0',blockb[i] = {0,0},mpb[i] = fan_huib[i] = 0;
	cin >> sss;for (int i = 1;i <= n;i++) c[i] = sss[i - 1] - '0';
	cin >> sss;for (int i = 1;i <= n;i++) d[i] = sss[i - 1] - '0';
	for (int i = 1;i <= n;i++){
		if (c[i] == 1){
			tota++;blocka[tota] = {(a[i] == 0),(a[i] == 1)};mpa[i] = tota;
			while (i < n && c[i + 1] == 1){
				i++;mpa[i] = tota;
				if(a[i] == 0) blocka[tota].first++;
				else blocka[tota].second++;
			}
		}
	}for (int i = 1;i <= n;i++){
		if (d[i] == 1){
			totb++;blockb[totb] = {(b[i] == 0),(b[i] == 1)};mpb[i] = totb;
			while (i < n && d[i + 1] == 1){
				i++;mpb[i] = totb;
				if(b[i] == 0) blockb[totb].first++;
				else blockb[totb].second++;
			}
		}
	}int cnt = 0;for (int i = 1;i <= n;i++){
		if (c[i] == 0 && d[i] == 0) cnt += (a[i] == b[i]);
		else if (c[i] == 1 && d[i] == 1) continue;
		else if (c[i] == 1 && d[i] == 0){
			if (b[i] == 0){if (blocka[mpa[i]].first != 0) blocka[mpa[i]].first--,cnt++;}
			else {if (blocka[mpa[i]].second != 0) blocka[mpa[i]].second--,cnt++;}
		}else{
			if (a[i] == 0){if (blockb[mpb[i]].first != 0) blockb[mpb[i]].first--,cnt++;}
			else {if (blockb[mpb[i]].second != 0) blockb[mpb[i]].second--,cnt++;}
		}
	}for (int i = 1;i <= n;i++){
		if (c[i] == 1 && d[i] == 1){
			if (blocka[mpa[i]].first != 0 && blockb[mpb[i]].first != 0) blocka[mpa[i]].first--,blockb[mpb[i]].first--,cnt++;
			else if (blocka[mpa[i]].second != 0 && blockb[mpb[i]].second != 0) blocka[mpa[i]].second--,blockb[mpb[i]].second--,cnt++;
		}
	}cout << cnt << "\n";
}
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	int T;cin >> T;while (T--) solve();
	return 0;
}
/*
1
6
011101
111010
111010
101101

4
*/
