#include <bits/stdc++.h>
#define endl '\n' 
constexpr int maxn=200010;
using namespace std;
int n, t, ans;
string s1, s2, t1, t2;
int a1[maxn], a2[maxn];
int main(void){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while (t--){
		ans=0;
		cin>>n;
		cin>>s1>>s2>>t1>>t2;
		int lst=-1;
		for (int i=0; i<n; i++){
			a1[i]=s1[i]-48;
			a2[i]=s2[i]-48;
		}
		for (int i=0; i<n; i++){
			if (t1[i]=='0'){
				sort(a1+lst+1, a1+i);
				lst=i;
			}
		}
		lst=-1;
		for (int i=0; i<n; i++){
			if (t2[i]=='0'){
				sort(a2+lst+1, a2+i);
				lst=i;
			}
		}
		queue<int> q1, q2;
		for (int i=0; i<n; i++){
			if (t1[i]=='0'){
				while (!q1.empty()) q1.pop();
				while (!q2.empty()) q2.pop();
				continue;
			}
			if (a1[i]!=a2[i]){
				if (a1[i]==0){
					if (!q2.empty()){
						swap(a1[q2.front()], a1[i]);
						q2.pop();
					}
					else q1.push(i);
				}
				else{
					if (!q1.empty()){
						swap(a1[q1.front()], a1[i]);
						q1.pop();
					}
					else q2.push(i);
				}
			}
		}
		while (!q1.empty()) q1.pop();	
		while (!q2.empty()) q2.pop();
		for (int i=0; i<n; i++){
			if (t2[i]=='0'){
				while (!q1.empty()) q1.pop();
				while (!q2.empty()) q2.pop();
				continue;
			}
			if (a1[i]!=a2[i]){
				if (a2[i]==0){
					if (!q2.empty()){
						swap(a2[q2.front()], a2[i]);
						q2.pop();
					}
					else q1.push(i);
				}
				else{
					if (!q1.empty()){
						swap(a2[q1.front()], a2[i]);
						q1.pop();
					}
					else q2.push(i);
				}
			}
		}
		for (int i=0; i<n; i++){
			ans+=(a1[i]==a2[i]?1:0);
		}
		cout<<ans<<endl;
	}
} 
