#include <bits/stdc++.h>
#define rep(i, a, b) for(int i=a; i<b; i++)
using namespace std;
const int N = 1e5 + 5;
int T, n, ans;
string s1, s2, t1, t2;
int diff(int x, int y){
	int cnt = n;
	rep(i, 0, n) cnt -= (x>>i&1) ^ (y>>i&1);
	return cnt;
}
int b2d(string s){
	int res = 0;
	rep(i, 0, n) res |= (s[i] - '0') << i;
	return res;
}
int change(int x, int i){return x ^ (1 << i);}
set<pair<int, int>> vis;
void dfs(int x, int y){
	if(vis.count({x, y})) return;
	vis.insert({x, y});
	ans = max(ans, diff(x, y));
	rep(i, 1, n){
		if(t1[i] == '0' || t1[i-1] == '0') continue;
		if((x >> i & 1) == (x >> (i-1) & 1)) continue;
		dfs(change(change(x, i), i-1), y);
	}
	rep(i, 1, n){
		if(t2[i] == '0' || t2[i-1] == '0') continue;
		if((y >> i & 1) == (y >> (i-1) & 1)) continue;
		dfs(x, change(change(y, i), i-1));
	}
}
signed main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin.tie(nullptr) -> sync_with_stdio(false);
	for(cin >> T; T --> 0;){
		cin >> n >> s1 >> s2 >> t1 >> t2; ans = 0;
		if(n <= 10){
			vis.clear(); dfs(b2d(s1), b2d(s2));
			cout << ans << "\n";
			continue;
		}
		rep(i, 1, n) if(s1[i] != s1[0]) goto brk;
		rep(i, 0, n) ans += (s1[i] == s2[i]);
		cout << ans << "\n";
		continue; brk:
		if(t1 == t2){
			int a0 = 0, a1 = 0;
			int b0 = 0, b1 = 0;
			rep(i, 0, n){
				if(t1[i] == '0'){
					ans += min(a0, b0) + min(a1, b1) + (s1[i] == s2[i]);
					a0 = a1 = b0 = b1 = 0;
					continue;
				}
				s1[i] == '0' ? a0++ : a1++;
				s2[i] == '0' ? b0++ : b1++;
			}
			ans += min(a0, b0) + min(a1, b1);
			cout << ans << "\n";
			continue;
		}
	}
	return 0;
}
