#include <bits/stdc++.h>
using namespace std;
int read(){
	int s = 0, f = 1;char ch = getchar();
	while(!isdigit(ch)){if(ch == '-')f = -1;ch = getchar();}
	while(isdigit(ch)){s = s * 10 + ch - '0';ch = getchar();}
	return s * f;
}
const int MAXN = 1e5 + 5;
int t, n, a[MAXN], b[MAXN], s1[MAXN], s2[MAXN], used[MAXN], used2[MAXN];
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	t = read();
	while(t --){
		n = read();
		memset(used, 0, sizeof(used));
		memset(used2, 0, sizeof(used2));
		int ans = 0;
		for(int i = 1;i <= n;i ++)scanf("%1d", &a[i]);
		for(int i = 1;i <= n;i ++)scanf("%1d", &b[i]);
		for(int i = 1;i <= n;i ++)scanf("%1d", &s1[i]);
		for(int i = 1;i <= n;i ++)scanf("%1d", &s2[i]);
		for(int i = 2;i < n;i ++){
			if(!s1[i - 1] && ! s1[i + 1])s1[i] = 0;
			if(!s2[i - 1] && ! s2[i + 1])s2[i] = 0;
		}
		int ct = 0, ct2 = 0, cta = 0, ctb = 0, pos = 1, pos2 = 1, last = 1, last2 = 1;
		for(;pos <= n || pos2 <= n;){
			while(pos <= n && s1[pos]){
				if(a[pos])ct ++;
				else ct2 ++;
				pos ++;
			} 
			while(pos2 <= n && s2[pos2]){
				if(b[pos2])cta ++;
				else ctb ++;
				pos2 ++;
			}
//			printf("%d %d %d %d %d %d %d\n", pos, pos2, ct, ct2, cta, ctb, ans);
			if(pos < pos2){
				if(pos <= n && a[pos] && cta)ans ++, cta --;
				if(pos <= n && !a[pos] && ctb)ans ++, ctb --;
				int h = min(ct, cta), g = min(ct2, ctb);
				if(last2 <= last){
					ans += h + g;
					ct = ct2 = 0, cta -= h, ctb -= g;
					last = pos;
					pos ++;
				}
				else{
					h = min(h, pos - last2 - 1), g = min(g, pos - last2 - 1);
					ans += h + g;
					ct = ct2 = 0, cta -= h, ctb -= g;
					last = pos;
					pos ++;
				}
			}
			else if(pos > pos2){
				if(pos2 <= n && b[pos2] && ct)ans ++, ct --;
				if(pos2 <= n && !b[pos2] && ct2)ans ++, ct2 --;
				int h = min(ct, cta), g = min(ct2, ctb);
//				printf("%d %d %d %d\n", ct, ct2, cta, ctb);
				if(last <= last2){
					ans += h + g;
					cta = ctb = 0, ct -= h, ct2 -= g;
					last2 = pos2;
					pos2 ++;
				}
				else{
					h = min(h, pos2 - last - 1), g = min(g, pos2 - last - 1);
					ans += h + g;
					cta = ctb = 0, ct -= h, ct2 -= g;
					last2 = pos2;
					pos2 ++;
				}
			}
			else{
				int h = min(ct, cta), g = min(ct2, ctb);
				ans += h + g;
				if(pos <= n)ans += (a[pos] == b[pos]);
				ct = ct2 = cta = ctb = 0;
				last = pos, last2 = pos;
				pos ++, pos2 ++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
} 
