#include <bits/stdc++.h>
using namespace std;

string s1, s2, 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;
	while (t--) {
		int n;
		cin >> n;
		cin >> s1 >> s2 >> t1 >> t2;
		int cnt = 0;
		if (t1 == t2) {
			int a=0, b=0, c=0, d=0;
			for (int i = 0; i < n; i++) {
				if (t1[i] == '0') {
					cnt += min(a, c) + min(b, d);
					if (s1[i] == s2[i]) cnt++;
					a=0, b=0, c=0, d=0;
					continue;
				}
				if (s1[i] == '0') a++;
				if (s1[i] == '1') b++;
				if (s2[i] == '0') c++;
				if (s2[i] == '1') d++;
			}
			cnt += min(a, c) + min(b, d);
			cout << cnt << endl;
			continue;
		}
		for (int i = 0; i < n; i++) {
			if (s1[i] == s2[i]) cnt++;
		}
		cout << cnt << endl;
	}
	return 0;
}
