#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mininf = 1e9 + 13;
#define pb emplace_back
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0' or ch>'9'){if(ch=='-'){f=-1;}ch=getchar();}while(ch>='0' and ch<='9'){x=(x<<3)+(x<<1)+(ch^48);ch=getchar();} return x * f;}
inline void write(int x){if(x<0){putchar('-');x=-x;}if(x>=10){write(x/10);}putchar(x%10+'0');}
#define put() putchar(' ')
#define endl puts("")
const int MAX = 1e5 + 10;

int a[MAX], b[MAX], c[MAX], d[MAX];
int cnt[MAX], cnt2[MAX];
int cnt3[MAX], cnt4[MAX];

void solve(){
	int n = read();
	for(int i = 1; i <= n; i++){
		char ch = getchar();
		while(ch != '0' and ch != '1')	ch = getchar();
		a[i] = ch - '0';
	}
	for(int i = 1; i <= n; i++){
		char ch = getchar();
		while(ch != '0' and ch != '1')	ch = getchar();
		b[i] = ch - '0';
	}
	for(int i = 1; i <= n; i++){
		char ch = getchar();
		while(ch != '0' and ch != '1')	ch = getchar();
		c[i] = ch - '0';
	}
	for(int i = 1; i <= n; i++){
		char ch = getchar();
		while(ch != '0' and ch != '1')	ch = getchar();
		d[i] = ch - '0';
	}
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(c[i] == 0){
			if(a[i])	cnt[i] = 1;
			else cnt2[i] = 1;
		}else{
			int l = i;
			if(a[i])	cnt[i] = 1;
			else cnt2[i] = 1;
			while(l + 1 <= n and c[l + 1]){
				l++;	
				if(a[l])	cnt[i]++;
				else cnt2[i]++;
			}
			i = l;
		}
	}
	for(int i = 1; i <= n; i++){
		if(d[i] == 0){
			if(b[i])	cnt3[i] = 1;
			else cnt4[i] = 1;
		}else{
			int l = i;
			if(b[i])	cnt3[i] = 1;
			else cnt4[i] = 1;
			while(l + 1 <= n and d[l + 1]){
				l++;	
				if(b[l])	cnt3[i]++;
				else cnt4[i]++;
			}
			i = l;
		}
	}	
	int now0 = 0, now1 = 0, now2 = 0, now3 = 0;
	for(int i = 1; i <= n; i++){
		now0 += cnt[i], now1 += cnt2[i], now2 += cnt3[i], now3 += cnt4[i];
		if(now0 and now2)	ans++, now0--, now2--;
		else if(now1 and now3){
			ans++, now1--, now3--;
		}else{
			if(now0)	now0--;
			if(now1)	now1--;
			if(now2)	now2--;
			if(now3)	now3--;
		}
	}
	write(ans), endl;
	for(int i = 1; i <= n + 1; i++) a[i] = b[i] = c[i] = d[i] = cnt[i] = cnt2[i] = cnt3[i] = cnt4[i] = 0;
}

signed main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int t = read();
	while(t--)	solve();
	return 0;
}