#include <bits/stdc++.h>
#define pii pair<int, int>
#define fir first
#define sec second
using namespace std;

const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;

int T, n;
int a[N], b[N], s[N], t[N], cnt1[N][2], cnt2[N][2], pos1[N], pos2[N];
string str;

int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	cin >> T;
	while (T--){
		cin >> n >> str;
		for (int i = 0; i < n; i++) a[i + 1] = str[i] - '0';
		cin >> str;
		for (int i = 0; i < n; i++) b[i + 1] = str[i] - '0';
		cin >> str;
		for (int i = 0; i < n; i++) s[i + 1] = str[i] - '0';
		cin >> str;
		for (int i = 0; i < n; i++) t[i + 1] = str[i] - '0';
		memset(pos1, 0, sizeof(pos1));
		memset(pos2, 0, sizeof(pos2));
		memset(cnt1, 0, sizeof(cnt1));
		memset(cnt2, 0, sizeof(cnt2));
		int p = 0, q = 0;
		for (int i = 1; i <= n; i++){
			if (s[i] == 0) cnt1[++p][a[i]]++, pos1[i] = p; 
			else if (s[i - 1] == 0 && s[i] == 1) cnt1[++p][a[i]]++, pos1[i] = p;
			else if (s[i] == 1) cnt1[p][a[i]]++, pos1[i] = p;
			if (t[i] == 0) cnt2[++q][b[i]]++, pos2[i] = q;
			else if (t[i - 1] == 0 && t[i] == 1) cnt2[++q][b[i]]++, pos2[i] = q;
			else if (t[i] == 1) cnt2[q][b[i]]++, pos2[i] = q;
		}
		int ans = 0;
		for (int i = 1; i <= n; i++){
			if (cnt1[pos1[i]][0] && cnt2[pos2[i]][0]) ans++, cnt1[pos1[i]][0]--, cnt2[pos2[i]][0]--;
			else if (cnt1[pos1[i]][1] && cnt2[pos2[i]][1]) ans++, cnt1[pos1[i]][1]--, cnt2[pos2[i]][1]--;
		}
		cout << ans << endl;
	}
	return 0;
}

