#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+5;
struct gjc{
int l,r;
int n1,n0;
}g1[maxn],g2[maxn];
int num1[maxn][3],num0[maxn][3];
string s1,s2,t1,t2;
int calc1(int id,int l,int r){
return num1[r][id]-num1[l-1][id];
}
int calc0(int id,int l,int r){
return num0[r][id]-num0[l-1][id];
}
bool check(int id1,int id2){
if(g1[id1].l<=g2[id2].r&&g1[id1].r>=g2[id2].l)return true;
return false;
}
int gjc(int x){
return max(x,0);
}
void solve(){
memset(num1,0,sizeof(num1));
memset(num0,0,sizeof(num0));
memset(g1,0,sizeof(g1));
memset(g2,0,sizeof(g2));
int n;
cin>>n;
cin>>s1>>s2>>t1>>t2;
s1 = " "+s1; s2 = " "+s2;
t1 = " "+t1; t2 = " "+t2;
if(t1[1] == '1'&&t1[2] == '0')t1[1] = '0';
if(t1[n] == '1'&&t1[n-1] == '0')t1[n] = '0';
if(t2[1] == '1'&&t2[2] == '0')t2[1] = '0';
if(t2[n] == '1'&&t2[n-1] == '0')t2[n] = '0';
for(int i = 2;i<n;i++){
if(t1[i-1] == '0'&&t1[i+1] == '0')t1[i] = '0';
if(t2[i-1] == '0'&&t2[i+1] == '0')t2[i] = '0';
}
for(int i = 1;i<=n;i++){
if(t1[i] == '1')num1[i][1] = num1[i-1][1],num0[i][1] = num0[i-1][1];
else{
num1[i][1] = num1[i-1][1]+(s1[i] == '1');
num0[i][1] = num0[i-1][1]+(s1[i] == '0');
}
if(t2[i] == '1')num1[i][2] = num1[i-1][2],num0[i][2] = num0[i-1][2];
else{
num1[i][2] = num1[i-1][2]+(s2[i] == '1');
num0[i][2] = num0[i-1][2]+(s2[i] == '0');
}
}
int tot1 = 0,tot2 = 0;
bool f = 0;
for(int i = 1;i<=n;i++){
if(f&&t1[i] == '1'){
g1[tot1].n1+=(s1[i] == '1');
g1[tot1].n0+=(s1[i] == '0');
continue;
}
if(f&&t1[i] == '0'){
g1[tot1].r = i-1;
f = 0;
continue;
}
if(!f&&t1[i] == '1'){
f = 1;
g1[++tot1].l = i;
g1[tot1].n1+=(s1[i] == '1');
g1[tot1].n0+=(s1[i] == '0');
}
}
if(f)g1[tot1].r = n,f = 0;
for(int i = 1;i<=n;i++){
if(f&&t2[i] == '1'){
g2[tot2].n1+=(s2[i] == '1');
g2[tot2].n0+=(s2[i] == '0');
continue;
}
if(f&&t2[i] == '0'){
g2[tot2].r = i-1;
f = 0;
continue;
}
if(!f&&t2[i] == '1'){
f = 1;
g2[++tot2].l = i;
g2[tot2].n1+=(s2[i] == '1');
g2[tot2].n0+=(s2[i] == '0');
}
}
if(f)g2[tot2].r = n,f = 0;
int ans = 0;
for(int i = 1;i<=n;i++){
if(t1[i] == '0'&&t2[i] == '0')ans+=(s1[i] == s2[i]);
}
for(int i = 1;i<=tot1;i++){
int n11 = min(calc1(2,g1[i].l,g1[i].r),g1[i].n1);
int n00 = min(calc0(2,g1[i].l,g1[i].r),g1[i].n0);
ans+=n11+n00;
g1[i].n1-=n11;
g1[i].n1 = gjc(g1[i].n1);
g1[i].n0-=n00;
g1[i].n0 = gjc(g1[i].n0);
}
for(int i = 1;i<=tot2;i++){
int n11 = min(calc1(1,g2[i].l,g2[i].r),g2[i].n1);
int n00 = min(calc0(1,g2[i].l,g2[i].r),g2[i].n0);
ans+=n11+n00;
g2[i].n1-=n11;
g2[i].n1 = gjc(g2[i].n1);
g2[i].n0-=n00;
g2[i].n0 = gjc(g2[i].n0);
}
for(int i = 1;i<=tot1;i++){
for(int j = 1;j<=tot2;j++){
if(check(i,j)){
int n11 = min(g1[i].n1,g2[j].n1),n00 = min(g1[i].n0,g2[j].n0);
ans+=n00+n11;
g1[i].n1-=n11;
g2[j].n1-=n11;
g1[i].n0-=n00;
g2[j].n0-=n00;
}
}
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
int t;
cin>>t;
while(t--)solve();
return 0;
}