#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const int N = 100005;

int n;
bool a[N] = {};
bool b[N] = {};
bool at[N] = {};
bool bt[N] = {};
int cnt = 0; 

struct period{int cnt1; int cnt0;};
period ap[N] = {}, bp[N] = {};
int acntp = 0, bcntp = 0;
int abl[N] = {};
int bbl[N] = {};

int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	
	int T;  std:: scanf("%d",&T);
	while(T --){
		//clear
		cnt = 0;
		acntp = 0; bcntp = 0;
		for(int i=0; i<N; ++i)  {ap[i].cnt1 = 0; ap[i].cnt0 = 0;}
		for(int i=0; i<N; ++i)  {bp[i].cnt1 = 0; bp[i].cnt0 = 0;}
		memset(abl, 0, sizeof abl);
		memset(bbl, 0, sizeof bbl);
		
		std:: scanf("%d", &n);
		for(int i=1; i<=n; ++i)  std:: scanf("%1d", &a[i]);
		for(int i=1; i<=n; ++i)  std:: scanf("%1d", &b[i]);
		for(int i=1; i<=n; ++i)  std:: scanf("%1d", &at[i]);
		for(int i=1; i<=n; ++i)  std:: scanf("%1d", &bt[i]);
		
		//预处理活动段
		for(int i=1; i<=n; ++i){     //a活动段 
			if(at[i] == 1){
				if(at[i-1] == 0)  ++ acntp;
				abl[i] = acntp;
				if(a[i] == 1)  ++ ap[acntp].cnt1;
				if(a[i] == 0)  ++ ap[acntp].cnt0;
			}
		} 
		for(int i=1; i<=n; ++i){     //b活动段 
			if(bt[i] == 1){
				if(bt[i-1] == 0)  ++ bcntp;
				bbl[i] = bcntp;
				if(b[i] == 1)  ++ bp[bcntp].cnt1;
				if(b[i] == 0)  ++ bp[bcntp].cnt0;
			}
		} 
		
//		std:: printf("abl[]:  ");
//		for(int i=1; i<=n; ++i)  std:: printf("%d ", abl[i]);
//		std:: printf("\nbbl[]:  ");
//		for(int i=1; i<=n; ++i)  std:: printf("%d ", bbl[i]);
//		std:: printf("\n\n");
		
		//开始贪心 
		for(int i=1; i<=n; ++i){
			if(at[i]==1 && bt[i]==1){          //上下均活动 
				
				if(ap[abl[i]].cnt1 && bp[bbl[i]].cnt1){  //全是 1 时
					-- ap[abl[i]].cnt1;
					-- bp[bbl[i]].cnt1;
					++ cnt;
				}else if(ap[abl[i]].cnt0 && bp[bbl[i]].cnt0){  //全是 0 时
					-- ap[abl[i]].cnt0;
					-- bp[bbl[i]].cnt0;
					++ cnt;
				}
			}else if(at[i]==1 && bt[i]==0){    //上活动, 下静止 (以下面为准) 
				if(b[i] == 1){
					if(ap[abl[i]].cnt1){
						-- ap[abl[i]].cnt1;
						++ cnt;
					}
				}else if(b[i] == 0){
					if(ap[abl[i]].cnt0){
						-- ap[abl[i]].cnt0;
						++ cnt;
					}
				}
			}else if(at[i]==0 && bt[i]==1){    //下活动, 上静止 (以上面为准) 
				if(a[i] == 1){
					if(bp[bbl[i]].cnt1){
						-- bp[bbl[i]].cnt1;
						++ cnt;
					}
				}else if(a[i] == 0){
					if(bp[bbl[i]].cnt0){
						-- bp[bbl[i]].cnt0;
						++ cnt;
					}
				}
			}else if(at[i]==0 && bt[i]==0){    //上下均静止 
				cnt += (a[i]==b[i]);
			}
		}
		
		std:: printf("%d\n", cnt);
	}
	return 0;
}
