#include <bits/stdc++.h>
#define C__ const
using namespace std;
inline void filopen(string path) {
	cin.tie(0)->sync_with_stdio(0);
	freopen((path + ".in").c_str(), "r", stdin);
	freopen((path + ".out").c_str(), "w", stdout);
}
C__ int N_ = 1e5 + 10;
bool s[2][N_], t[2][N_];
int n, fa[N_], cnt[2][N_];
int ffind(int u) { return fa[u] == u ? u : fa[u] = ffind(fa[u]); }
void slove() {
	cin >> n;
	for (int c : {0, 1})
		for (int i = 1; i <= n; i++) {
			char x; cin >> x;
			s[c][i] = (x == '1');
		}
	for (int c : {0, 1})
		for (int i = 1; i <= n; i++) {
			char x; cin >> x;
			t[c][i] = (x == '1');
		}
	for (int i = 1; i <= n; i++) fa[i] = i;
	for (int c : {0, 1}) {
		for (int i = 1; i < n; i++) {
			if (t[c][i] && t[c][i + 1]) {
				int u = i, v = i + 1;
				u = ffind(u), v = ffind(v);
				fa[v] = u;
			}
		}
	}
	for (int i = 1; i <= n; i++) ++cnt[s[0][i]][ffind(i)];
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int now = s[1][i], pos = ffind(i);
		if (cnt[now][pos]) {
			++ans, --cnt[now][pos];
		}
	}
	cout << ans << "\n";
}
void celar() {
	memset(cnt, 0, sizeof cnt);
}
signed main() {
	filopen("edit");
	int T; cin >> T;
	while (T--) slove(), celar();
	return 0;
}
