#include <bits/stdc++.h>
using namespace std;

const int maxn=1e5+100;
char s1[maxn], s2[maxn], t1[maxn], t2[maxn];

int belong1[maxn], belong2[maxn];

struct area {
	int cnt[4];
} sa1[maxn], sa2[maxn];
int sa1tot, sa2tot;

inline int min3(int a, int b, int c){
	return min(min(a, b), c);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	int t;
	cin >> t;
	while (t--){
		memset(sa1, 0, sizeof sa1);
		memset(sa2, 0, sizeof sa2);
		sa1tot = sa2tot = 0;
		
		int n;
		cin >> n;
		cin >> s1+1 >> s2+1 >> t1+1 >> t2+1;
		
		for (int i=1; i<=n; i++){
			// new block?
			bool n1 = (t1[i]=='0' || t1[i]!=t1[i-1]);
			bool n2 = (t2[i]=='0' || t2[i]!=t2[i-1]);
//			printf("#%d n1=%d n2=%d\n", i, n1, n2);
			sa1tot += n1;
			sa2tot += n2;
			
			sa1[sa1tot].cnt[s1[i]-'0']++;
			sa2[sa2tot].cnt[s2[i]-'0']++;
			
			belong1[i] = sa1tot;
			belong2[i] = sa2tot;
		}
		
		int ans=0;
		for (int i=1; i<=n; i++){
			int bl1 = belong1[i], bl2=belong2[i];
			if (sa1[bl1].cnt[0] && sa2[bl2].cnt[0]){
//				printf("%d use %d # %d %d\n", i, 0, sa1[bl1].cnt[0], sa2[bl2].cnt[0]);
				sa1[bl1].cnt[0]--;
				sa2[bl2].cnt[0]--;
				ans++;
			} else if (sa1[bl1].cnt[1] && sa2[bl2].cnt[1]){
//				printf("%d use %d\n", i, 1);
				sa1[bl1].cnt[1]--;
				sa2[bl2].cnt[1]--;
				ans++;
			}
		}
		cout << ans << '\n';
	}
	
	return 0;
}
 
