#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
const int N = 1e5 + 5;
struct Node{
	int l, r;
}a1[N], a2[N];
int T, n, cnt1, cnt2;
char s1[N], s2[N], t1[N], t2[N];
void init(Node *a, int &cnt, char *t){
	int lst = -1;
	for(int i = 1; i <= n; ++i){
		if(t[i] == '0'){
			if(lst != -1 && (i - 1) - lst + 1 > 1) a[++cnt] = {lst, i - 1};
			lst = -1;
		}else if(lst == -1) lst = i;
	}
}
void solve(int cnt, char *s, char t[], Node a[]){
	for(int i = 1; i <= cnt; ++i){
		int dif0 = 0, dif1 = 0;
		for(int j = a[i].l; j <= a[i].r; ++j){
			if(s[j] == '1') dif1++;
			else dif0++;
		}
		for(int j = a[i].r; j >= a[i].l; --j){
			if(t[j] == '1'){
				if(dif1) s[j] = '1', dif1--;
				else s[j] = '0', dif0--;
			}else{
				if(dif0) s[j] = '0', dif0--;
				else s[j] = '1', dif1--;
			}
		}
	}
}
signed main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> T;
	while(T--){
		cnt1 = cnt2 = 0;
		cin >> n >> s1 + 1 >> s2 + 1 >> t1 + 1 >> t2 + 1;
		init(a1, cnt1, t1), init(a2, cnt2, t2);
		solve(cnt2, s2, s1, a2), solve(cnt1, s1, s2, a1);
		int ans = 0;
		for(int i = 1; i <= n; ++i) ans += (s1[i] == s2[i]);
		cout << ans << endl;
	}
	return 0;
}
/*
1
10
0110111100
1111111100
1110000100
0110111011
*/
