#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
typedef vector<int> vint;
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin >> t;
	while(t--){
		int n;
		cin >> n;
		string a,b;
		vint sa,sb;
		cin >> a >> b;
		for(int i=0;i<n;i++){
			char s;
			cin >> s;
			if(s=='0') sa.push_back(i);
		}
		sa.push_back(n);
		for(int i=0;i<n;i++){
			char s;
			cin >> s;
			if(s=='0') {
				sb.push_back(i);
			}
		}
		sb.push_back(n);
		array<priority_queue<int,vint,greater<int>>,2> posa{},posb{};
		for(int i=0;i<n;i++){
			posa[a[i]-'0'].push(i);
			posb[b[i]-'0'].push(i);
		}
		int l=0,r=0,ans=0;
	
		for(int i=0;i<n;i++){
			posa[a[i]-'0'].pop();
			posb[b[i]-'0'].pop();
			if(a[i]!=b[i]){
				bool flag=false;
				int apos=n,bpos=n;
				if(!posb[a[i]-'0'].empty() && posb[a[i]-'0'].top() < sb[r]){
					bpos= posb[a[i]-'0'].top();
				}
				if(!posa[b[i]-'0'].empty() && posa[b[i]-'0'].top() < sa[l]){
					apos= posa[b[i]-'0'].top();
				}
				if(apos==n&&bpos==n){
					flag=false;
				} else if(apos<bpos){
					flag=true;
					posa[b[i]-'0'].pop();
					posa[a[i]-'0'].push(apos);
					swap(a[i],a[apos]);
				} else {
					flag=true;
					posb[a[i]-'0'].pop();
					posb[b[i]-'0'].push(bpos);
					swap(b[i],b[bpos]);
				}
				if(flag){
					ans++;
				}
			} else {
				ans++;
			}
			if(i==sa[l]) l++;
			if(i==sb[r]) r++;
		}
		cout << ans << endl;
	}
} 
