#include <bits/stdc++.h>
using namespace std;
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int T;
	scanf("%d", &T);
	for (int I = 0; I < T; I++){
		int n, r = 0;
		char x;
		scanf("%d", &n);
		string a = "", b = "";
		vector<int> ai;
		vector<int> bi;
		getchar();
		for(int i = 0; i < n;i++) a += getchar();
		getchar();
		for(int i = 0; i < n;i++) b += getchar();
		getchar();
		for(int i = 0;i < n;i++) if (getchar()=='0')ai.push_back(i);
		getchar();
		for(int i = 0;i < n;i++) if (getchar()=='0')bi.push_back(i);
//		if (I != 6) continue;
//		cout << a << endl << b << endl;
//		for(int i = 0; i < ai.size();i++) cout << ai[i] << ' ';
//		cout << endl;
//		for(int i = 0; i < bi.size();i++) cout << bi[i] << ' ';
//		cout << endl;
		ai.push_back(n);
		bi.push_back(n);
		int ax = 0, bx = 0, a0 = 0, a1 = 0, b0 = 0, b1 = 0;
//		bool as = 0, bs = 0;
		while (ax < n || bx < n){
//			int aii = ai[0], bii = bi[0];
//			if(as) aii = ax;
//			if(bs) bii = bx;
			if (ax <= bx) {
//				as = 0;
				if (ax == ai[0]){
//					cout << a[ax];
					if(a[ax] == '0')a0++;
					else a1++;
					ax++;
					ai.erase(ai.begin());
//					as = 1;
				}
				else while (ax < ai[0]) {
//					cout << a[ax];
					if(a[ax] == '0')a0++;
					else a1++;
					ax++;
				}
			} else {
//				bs = 0;
				if (bx == bi[0]){
//					cout << b[bx];
					if(b[bx] == '0')b0++;
					else b1++;
					bx++;
					bi.erase(bi.begin());
//					bs = 0;
				}
				else while (bx < bi[0]) {
//					cout << b[bx];
					if(b[bx] == '0')b0++;
					else b1++;
					bx++;
				}
			}
//			cout << endl;
//			cout << ax << ' ' << bx << " | " << a0 << ' ' << a1 << " | " << b0 << ' ' << b1 << " | " << r << endl;
			int x = min(a0, b0);
			a0 -= x; b0 -= x; r+= x;
			x = min(a1, b1);
			a1 -= x; b1 -= x; r+= x;
			if(ax <= bx) {
				b1 -= a0;
				b0 -= a1;
				a0 = 0, a1 = 0;
			}
			if (bx <= ax){
				a1 -= b0;
				a0 -= b1;
				b0 = 0, b1 = 0;
			}
//			cout << ax << ' ' << bx << " | " << a0 << ' ' << a1 << " | " << b0 << ' ' << b1 << " | " << r << endl;
		}
		cout << r << endl;
	}
	return 0; 
}
