#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int maxn = 1e5;
int n, ans;
string s1, s2;
string t1, t2;
int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T;
	cin >> T;
	bool flag = false;
	int cnt10 = 0, cnt11 = 0;
	int cnt20 = 0, cnt21 = 0;
	while (T--) {
		flag = false, ans = 0;
		cin >> n;
		cin >> s1 >> s2;
		cin >> t1 >> t2;
		for (int i = 1; i < n; ++i) 
			if (s1[i] != s1[0]) {
				flag = true;
				break;
			}
		if (!flag) {
			for (int i = 0; i < n; ++i) 
				if (s2[i] == s1[i])
					++ans;
		} else {
			if (t1 == t2) {
				for (int i = 0; i < n; ++i) {
					if (t1[i] == '1') {
					cnt11 = cnt10 = 0;
					cnt20 = cnt21 = 0;
						while (i < n && t1[i] == '1') {
							if (s1[i] == '1') ++cnt11;
							else ++cnt10;
							if (s2[i] == '1') ++cnt21;
							else ++cnt20;
							++i;
						}
						--i;
						ans += min(cnt21, cnt11) + min(cnt10, cnt20);
					} else {
						while (i < n && t1[i] == '0') {
							ans += (s1[i] == s2[i]);
							++i;
						}
						--i;
					}
				} 
			} else ans = n;
		}
		cout << ans << '\n';
	}
	return 0;
}

