#include<bits/stdc++.h>
using namespace std;
template<typename T> void qr(T& x){
	x=0; char c=getchar(); int f=1;
	for(; !isdigit(c); c=getchar()) if(c=='-') f=-1;
	for(; isdigit(c); c=getchar()) x=x*10+(c-'0');
	x*=f;
}
template<typename T> void qw(T x){
	if(x<0) putchar('-'), x=-x;
	if(x>10) qw(x/10);
	putchar(x%10+'0');
}
const int N=2e5+10;
char sa[N], sb[N], tta[N], ttb[N];
int aa[N], bb[N]; deque<int> la[3], lb[3]; bool v[N];
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	int T; scanf("%d", &T);
	while(T--){
		int n; scanf("%d", &n);
		int res=0;
		scanf("%s", sa+1); scanf("%s", sb+1);
		scanf("%s", tta+1); scanf("%s", ttb+1);
		for(int i=1; i<=n; i++) if(isdigit(sa[i])) aa[i]=sa[i]-'0';
		for(int i=1; i<=n; i++) if(isdigit(sb[i])) bb[i]=sb[i]-'0';
		la[0].clear(); lb[0].clear();
		la[1].clear(); lb[1].clear();
		memset(v, 0, sizeof(v));
		
		for(int i=1; i<=n; i++){
			if(aa[i]!=bb[i]){
				for(int j=0; j<=1; j++){
					while(la[j].size() && v[la[j].front()]==2) la[j].pop_front();
					while(lb[j].size() && v[lb[j].front()]==2) lb[j].pop_front();
				}
				
				if(tta[i]=='0') la[0].clear(), la[1].clear(); 
				if(ttb[i]=='0') lb[0].clear(), lb[1].clear(); 
				if(tta[i]=='0' && ttb[i]=='0') res++;
				else{
					res++; v[i]=1;
					if(tta[i]=='0'){
						if(lb[aa[i]].size()){
							res--; int x=lb[aa[i]].front(); 
							res--, v[x]=2; //
							lb[aa[i]].pop_front(); 
						}
						else lb[bb[i]].push_back(i);
					}
					else if(ttb[i]=='0'){
						if(la[bb[i]].size()){
							res--; int x=la[bb[i]].front(); 
							res--, v[x]=2; //
							la[bb[i]].pop_front(); 
						}
						else la[aa[i]].push_back(i);
					}
					else{
						if(lb[aa[i]].size()){
							res--; int x=lb[aa[i]].front(); 
							res--, v[x]=2; //
							lb[aa[i]].pop_front(); 
						}
						else if(la[bb[i]].size()){
							res--; int x=la[bb[i]].front(); 
							res--, v[x]=2; //
							la[bb[i]].pop_front(); 
						}
						else lb[bb[i]].push_back(i), la[aa[i]].push_back(i);
					}
				}
			}
		}
		printf("%d\n", n-res);
	}
	return 0;
}
