#include <iostream>
using namespace std;

char exchange(char* str,char* judge, int len) {
	for (int i = 0; i < len; i++) {
		if(judge[i] == '1') {
			for(int j = i + 1; j < len; j++) {
				if(str[i] < str[j] && judge[j] == '1') {
					char temp = str[i];
					str[i] = str[j];
					str[j] = temp;
				}
			}
		}
	}
}

int main() {
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	cin >> T;
	for (int index = 0; index < T; index++) {
		int n;
		cin >> n;
		char s1[n],s2[n],t1[n],t2[n];
		cin >> s1 >> s2 >> t1 >> t2;
		int ans = 0;
		int sum1 = 0;
		int sum0 = 0;
		for (int i = 0; i < n; i++) {
			if(s1[i] == '0') {
				sum0++;
			} else {
				sum1++;
			}
		}
		if (sum1 == n || sum0 == n) {
			for(int i = 0; i < n; i++) {
				if(s1[i] == s2[i]) {
					ans++;
				}
			}
			cout << ans;
		} else {
			exchange(s1, t1, n);
			for(int i = 0; i < n; i++) {
				if(s2[i] != s1[i] && s2[i + 1] == s1[i] && t2[i] == '1' && t2[i + 1] == '1') {
					int temp = s2[i];
					s2[i] = s2[i + 1];
					s2[i + 1] = temp;
				}
			}
			for (int i = 0; i < n; i++) {
				if(s1[i] == s2[i]) {
					ans++;
				}
			}
			cout << ans << endl;
		}
	}
	fclose(stdin);
	fclose(stdout);
}


