#include<bits/stdc++.h>
#define LL long long
#define Maxn 100005
using namespace std;
int n,ans;
char sa[Maxn],sb[Maxn],ta[Maxn],tb[Maxn];
int qa,qb,pa,pb;
void slv(){
	scanf("%d%s%s%s%s",&n,sa+1,sb+1,ta+1,tb+1);
	ans = 0;
	qa = qb = pa = pb = 0;
	for(int i=1,cura=1,curb=1; i<=n; i++){
		if(ta[i] == '1'){
			if(cura <= i){
				while(cura<=n && ta[cura]=='1'){
					(sa[cura] == '1') ? (++qa) : (++pa);
					cura++;
				}
			}
		} else {
			qa = pa = 0; cura = i+1;
		}
		if(tb[i] == '1'){
			if(curb <= i){
				while(curb<=n && tb[curb]=='1'){
					(sb[curb] == '1') ? (++qb) : (++pb);
					curb++;
				}
			}
		} else {
			qb = pb = 0; curb = i+1;
		}
		
		if(ta[i]=='0' && tb[i]=='0'){
			ans += (sa[i] == sb[i]);
		} else if(ta[i] == '0'){
			if(sa[i] == '1'){
				if(qb){
					qb--;
					ans++;
				}
			} else {
				if(pb){
					pb--;
					ans++;
				}
			}
		} else if(tb[i] == '0'){
			if(sb[i] == '1'){
				if(qa){
					qa--;
					ans++;
				}
			} else {
				if(pa){
					pa--;
					ans++;
				}
			}
		} else {
			if(qa && qb){
				ans++;
				qa--;
				qb--;
				continue;
			}
			if(pa && pb){
				ans++;
				pa--;
				pb--;
				continue;
			}
		}
	}
	printf("%d\n",ans);
}
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int ttt; scanf("%d",&ttt);
	while(ttt--) slv();
	return 0;
}

