#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
bool a[MAXN], b[MAXN], fa[MAXN], fb[MAXN];
int ans[MAXN], ra[MAXN], rb[MAXN];
struct qj{
	int x, y;
}qa[MAXN / 2], qb[MAXN / 2];
int main(){
	freopen("edit.in", "r", stdin); 
	freopen("edit.out", "w", stdout); 
	int T;
	cin >> T;
	while(T--){
		memset(a, 0, sizeof(a));
		memset(b, 0, sizeof(b));
		memset(fa, 0, sizeof(fa));
		memset(fb, 0, sizeof(fb));
		memset(ra, 0, sizeof(ra));
		memset(rb, 0, sizeof(rb));
		memset(qa, 0, sizeof(qa));
		memset(qb, 0, sizeof(qb));
		memset(ans, 0, sizeof(ans));
		int n;
		cin >> n;
		string A, B;
		cin >> A >> B;
		string FA, FB;
		cin >> FA >> FB;
		for(int i = 1; i <= n; i++){
			a[i] = A[i - 1] - 48;
			b[i] = B[i - 1] - 48;
			fa[i] = FA[i - 1] - 48;
			fb[i] = FB[i - 1] - 48;
		}
		for(int i = 1; i <= n; i++){
			if(fa[i] == 1 && fa[i - 1] == 0 && fa[i + 1] == 0){
				fa[i] = 0;
			}
			if(fb[i] == 1 && fb[i - 1] == 0 && fb[i + 1] == 0){
				fb[i] = 0;
			}
		}
		int tota, totb;
		tota = totb = 0;
		for(int i = 1; i <= n; i++){
			if(fa[i] == 1){
				if(fa[i - 1] == 0){
					tota++;
				}
				ra[i] = tota;
				if(a[i] == 1){
					qa[tota].x++;
				}
				else{
					qa[tota].y++;
				}
			}
			if(fb[i] == 1){
				if(fb[i - 1] == 0){
					totb++;
				}
				rb[i] = totb;
				if(b[i] == 1){
					qb[totb].x++;
				}
				else{
					qb[totb].y++;
				}
			}
		}
		for(int i = 1; i <= n; i++){
			ans[i] = ans[i - 1];
			if(ra[i] == 0 && rb[i] == 0){
				ans[i] += ((a[i] ^ b[i]) ^ 1);
			}
			else{
				if(ra[i] != 0 && rb[i] == 0){
					if(b[i] == 1){
						if(qa[ra[i]].x > 0){
							qa[ra[i]].x--;
							ans[i]++; 
						}
						else{
							qa[ra[i]].y--;
						}
					}
					else{
						if(qa[ra[i]].y > 0){
							qa[ra[i]].y--;
							ans[i]++; 
						}
						else{
							qa[ra[i]].x--;
						}
					}
				}
				else if(ra[i] == 0 && rb[i] != 0){
					if(a[i] == 1){
						if(qb[rb[i]].x > 0){
							qb[rb[i]].x--;
							ans[i]++; 
						}
						else{
							qb[rb[i]].y--;
						}
					}
					else{
						if(qb[rb[i]].y > 0){
							qb[rb[i]].y--;
							ans[i]++; 
						}
						else{
							qb[rb[i]].x--;
						}
					}
				}
				else{
					if(qa[ra[i]].x > 0 && qb[rb[i]].x > 0){
						qa[ra[i]].x--;
						qb[rb[i]].x--;
						ans[i]++;
					}
					else if(qa[ra[i]].y > 0 && qb[rb[i]].y > 0){
						qa[ra[i]].y--;
						qb[rb[i]].y--;
						ans[i]++;
					}
				}
			}
		}
		cout << ans[n] << "\n";
	} 
	return 0;
}

