#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
string s1, s2, t1, t2;
int la1[2], la2[2], ans, n, tp; 
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int Cases;
	cin >> Cases;
	while(Cases--){
		cin >> n >> s1 >> s2 >> t1 >> t2;
		la1[0] = la1[1] = la2[0] = la2[1] = ans = 0;
		for(int i = 0; i < n; i++){
			if(t1[i] == '1'){
				int op = s2[i] - '0';
				la1[op] = max(la1[op], i);
				while(la1[op] < n && t1[la1[op]] == '1' && s1[la1[op]] != s2[i])
					la1[op]++;
				if(la1[op] < n && t1[la1[op]] == '1')
					swap(s1[i], s1[la1[op]]);
			}
			if(t2[i] == '1'){
				int op = s1[i] - '0';
				la2[op] = max(la2[op], i);
				while(la2[op] < n && t2[la2[op]] == '1' && s2[la2[op]] != s1[i])
					la2[op]++;
				if(la2[op] < n && t2[la2[op]] == '1')
					swap(s2[i], s2[la2[op]]);
			}
			if(s1[i] == s2[i])
				ans++;
		}
		cout << ans << "\n";
		
	}
} 
