#include<bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define ll long long
#define vc vector
#define vci vc<int>
#define psb push_back
using namespace std;
ll md;
inline ll ksm(ll a, ll b, ll md){
	ll ans = 1;
	while(b){
		if(b & 1) ans = ans * a % md;
		a = a * a % md;
		b >>= 1;
	}
	return ans;
}
inline ll read(){
	ll ans = 0;
	bool fl = 0;
	char c;
	while(1){
		c = getchar();
		if(c == '-' || ('0' <= c && c <= '9')) break;
	}
	if(c == '-') fl = 1;
	else ans = (int)(c - '0');
	while(1){
		c = getchar();
		if(c < '0' || c > '9') break;
		ans *= 10;
		ans += (int)(c - '0');
	}
	if(fl) ans = ans * -1;
	return ans;
}
int T, ans, n, cnt1, cnt2, sum1, sum2, fl;
string s, t, a, b;
void init(){
	ans = cnt1 = sum1 = cnt2 = sum2 = fl = 0;
}
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin >> T;
	while(T--){
		init();
		cin >> n >> s >> t >> a >> b;
		s = ' ' + s, t = ' ' + t, a = ' ' + a, b = ' ' + b;
		if(s == t){
			printf("%d\n", n);
			continue;
		}
		for(int i = 1; i < n; i++) fl &= (s[i] == s[i + 1]);
		if(fl){
			for(int i = 1; i <= n; i++)
				if(s[i] == t[i]) ans++;
			printf("%d\n", ans);
			continue;
		}
		for(int i = 1, j = 1;;){
			if(i > n && j > n) break;
			while(i <= n && a[i] == '1'){
				if(s[i] == '0') cnt1++;
				else sum1++;
				i++;
			}
			while(j <= n && b[j] == '1'){
				if(t[j] == '0') cnt2++;
				else sum2++;
				j++;
			}
			if(i < j){
				if(s[i] == '0') cnt1++;
				else sum1++;
				i++;
				int x = min(sum1, sum2), y = min(cnt1, cnt2);
				ans += x + y;
				cnt2 -= y + sum1 - x;
				sum2 -= x + cnt1 - y;
				cnt1 = sum1 = 0;
//				if(sum2 >= sum1 && cnt2 >= cnt1){
//					ans += cnt1 + sum1;
//					sum2 -= sum1;
//					cnt2 -= cnt1;
//					cnt1 = cnt2 = 0;
//				}
//				else if(sum2 >= sum1){
//					ans += sum1 + cnt2;
//				}
			}
			else if(i > j){
//				cout << cnt1 << ' ' << sum1 << endl;
				if(t[j] == '0') cnt2++;
				else sum2++;
				j++;
				int x = min(sum1, sum2), y = min(cnt1, cnt2);
				ans += x + y;
				cnt1 -= y + sum2 - x;
				sum1 -= x + cnt2 - y;
				cnt2 = sum2 = 0;
			}
			else{
				ans += min(sum1, sum2) + min(cnt1, cnt2);
				if(i < n && j < n){
					ans += (s[i] == t[j]);
					i++, j++;
				}
				cnt1 = cnt2 = sum1 = sum2 = 0;
			}
//			cout << i << ' ' << j << ' ' << cnt1 << ' ' << cnt2 << ' ' << sum1 << ' ' << sum2 << ' ' << ans << endl;
		}
		cout << ans << endl;
	}
	return 0;
}

