//60pts
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int N = 1e5 + 5;
int T, n, ans;
string s1, s2, t1, t2;
void dfs(int id, string ss1, string ss2){
	if(id > n){
		int num = 0;
		for(int i = 0; i < n; ++i) num += (ss1[i] == ss2[i]);
		ans = max(num, ans);
		return ;
	}
	if(ss1[id] == ss2[id]) dfs(id + 1, ss1, ss2);
	else {
		bool f = 0;
		if(t1[id] == '1' && t1[id + 1] == '1' && ss1[id] != ss1[id + 1]){
			swap(ss1[id], ss1[id + 1]); f = 1;
			dfs(id + 1, ss1, ss2);
		} 
		if(t2[id] == '1' && t2[id + 1] == '1' && ss2[id] != ss2[id + 1]){
			swap(ss2[id], ss2[id + 1]); f = 1;
			dfs(id + 1, ss1, ss2);
		}
		if(!f) dfs(id + 1, ss1, ss2);
	}
}
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	IOS;
	cin >> T;
	while(T--){
		cin >> n;
		ans = 0;
		cin >> s1 >> s2 >> t1 >> t2;
		bool A = 0;
		for(int i = 1; i < n; ++i) if(s1[i] != s1[0]) A = 1;
		if(!A){
			for(int i = 0; i < n; ++i) ans += (s1[i] == s2[i]);
			cout << ans << "\n";
			continue;
		} 
		if(t1 == t2){
			s1 = ' ' + s1, s2 = ' ' + s2, t1 = ' ' + t1, t2 = ' ' + t2;
			int pre10[N], pre11[N], pre20[N], pre21[N];
			int ans = 0, lst = 0;
			pre10[0] = pre11[0] = pre20[0] = pre21[0] = 0;
			for(int i = 1; i <= n; ++i) {
				pre10[i] = pre10[i - 1] + (s1[i] == '0');
				pre11[i] = pre11[i - 1] + (s1[i] == '1');
				pre20[i] = pre20[i - 1] + (s2[i] == '0');
				pre21[i] = pre21[i - 1] + (s2[i] == '1');
			}
			for(int i = 1; i <= n; ++i){
				if(t1[i] == '1') continue;
				int ans1 = min(pre10[i - 1] - pre10[lst], pre20[i - 1] - pre20[lst]);
				int ans2 = min(pre11[i - 1] - pre11[lst], pre21[i - 1] - pre21[lst]);
				lst = i;
				ans += ans1 + ans2 + (s1[i] == s2[i]);
			}
			int ans1 = min(pre10[n] - pre10[lst], pre20[n] - pre20[lst]);
			int ans2 = min(pre11[n] - pre11[lst], pre21[n] - pre21[lst]);
			ans += ans1 + ans2;
			cout << ans << endl;
			continue;
		}
		if(n <= 10) {
			dfs(0, s1, s2);
			cout << ans << "\n";
			continue;
		}
	}
	return 0;
}
