#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstdlib>
using namespace std;

const int SIZE = 1e5+5;

int n;
int s1[SIZE], s2[SIZE], t1[SIZE], t2[SIZE];
vector< pair<int,int> > g1, g2, l1, l2;
int b1[SIZE], b2[SIZE];

void parse(int s[], int t[], int b[], vector< pair<int,int> > &g, vector< pair<int,int> > &l) {
	int lst = 0, oc = 0, zc = 0;
	for (int i = 1; i <= n + 1; ++i) {
		if (i == n + 1 || t[i] == 0) {
			if (i - 1 > lst) {
				g.push_back(make_pair(oc, zc));
				l.push_back(make_pair(lst + 1, i - 1));
			}
			oc = zc = 0;
			lst = i;
		} else {
			b[i] = g.size();
			if (s[i] == 1) ++oc;
			else ++zc;
		}
	}
}

void solve() {
	scanf("%d",&n);
	vector< pair<int,int> >().swap(g1);
	vector< pair<int,int> >().swap(g2);
	vector< pair<int,int> >().swap(l1);
	vector< pair<int,int> >().swap(l2);
	for (int i = 1; i <= n; ++i) {
		b1[i] = b2[i] = -1;
	}
	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 = 1; i <= n; ++i) {
		scanf("%1d",t1+i);
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%1d",t2+i);
	}
	parse(s1, t1, b1, g1, l1);
	parse(s2, t2, b2, g2, l2);
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (b1[i] == -1 && b2[i] == -1 && s1[i] == s2[i]) {
			++ans;
		}
	}
	for (int i = 1; i <= n; ++i) {
		if (b1[i] != -1 && b2[i] == -1) {
			if (s2[i] == 0) {
				if (g1[b1[i]].second > 0) {
					--g1[b1[i]].second;
					++ans;
				}
			} else {
				if (g1[b1[i]].first > 0) {
					--g1[b1[i]].first;
					++ans;
				}
			}
		} else if (b1[i] == -1 && b2[i] != -1) {
			if (s1[i] == 0) {
				if (g2[b2[i]].second > 0) {
					--g2[b2[i]].second;
					++ans;
				}
			} else {
				if (g2[b2[i]].first > 0) {
					--g2[b2[i]].first;
					++ans;
				}
			}
		}
	}
	for (int i = 1; i <= n; ++i) {
		if (b1[i] != -1 && b2[i] != -1) {
			bool fa = false, fb = false;
			if (g1[b1[i]].first && g2[b2[i]].first) fa = true;
			if (g1[b1[i]].second && g2[b2[i]].second) fb = true;
			if (fa && !fb) {
				++ans;
				--g1[b1[i]].first;
				--g2[b2[i]].first;
			} else if (!fa && fb) {
				++ans;
				--g1[b1[i]].second;
				--g2[b2[i]].second;
			} else if (fa && fb) {
				++ans;
				--g1[b1[i]].first;
				--g2[b2[i]].first;
			}
		}
	}
	printf("%d\n",ans);
}

int main() {
	#ifdef fio
	freopen("../day0/edit/edit1.in","r",stdin);
	freopen("../test.out","w",stdout);
//	freopen("../test.in","r",stdin);
	#else
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	#endif
	int t;
	scanf("%d",&t);
	while (t--) {
		solve();
	}
}
