#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int t, n, ans, tot[2], p[N][2], cnt1[N][2], cnt2[N][2];
string s1, s2, t1, t2;
int main(){
freopen("edit.in","r",stdin);
freopen("edit.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin>>t;
while(t --){
cin>>n>>s1>>s2>>t1>>t2, ans = tot[0] = tot[1] = cnt1[1][0] = cnt1[1][1] = cnt2[1][0] = cnt2[1][1] = 0;
for(int i = 1;i <= n;i = -~i){
cnt1[tot[0] + 1][(s1[i - 1] - '0')] ++;
cnt2[tot[1] + 1][(s2[i - 1] - '0')] ++;
if(t1[i - 1] == '0') p[++tot[0]][0] = i, cnt1[tot[0] + 1][0] = cnt1[tot[0] + 1][1] = 0;
if(t2[i - 1] == '0') p[++tot[1]][1] = i, cnt2[tot[1] + 1][0] = cnt2[tot[1] + 1][1] = 0;
}
if(t1[n - 1] != '0') p[++tot[0]][0] = n + 1;
if(t2[n - 1] != '0') p[++tot[1]][1] = n + 1;
for(int i = 1, j = 1;i <= tot[0];i = -~i){
while(p[j][1] < p[i][0] && j <= tot[1]){
cnt1[i][(s1[p[i][0] - 1] - '0')] --;
int step1 = min(cnt1[i][0], cnt2[j][0]), step2 = min(cnt1[i][1], cnt2[j][1]);
cnt1[i][0] -= step1, cnt2[j][0] -= step1, cnt1[i][1] -= step2, cnt2[j][1] -= step2;
if(cnt2[j][0]) cnt1[i][1] -= cnt2[j][0], cnt2[j][0] = 0;
if(cnt2[j][1]) cnt1[i][0] -= cnt2[j][1], cnt2[j][1] = 0;
j ++, ans += step1 + step2, cnt1[i][(s1[p[i][0] - 1] - '0')] ++;
}
if(j > tot[1]) continue;
if(p[j][1] == p[i][0]){
if(p[j][1] != n + 1){
ans += (s1[p[i][0] - 1] == s2[p[j][1] - 1]);
cnt1[i][(s1[p[i][0] - 1] - '0')] --;
cnt2[j][(s2[p[j][1] - 1] - '0')] --;
}
int step1 = min(cnt1[i][0], cnt2[j][0]), step2 = min(cnt1[i][1], cnt2[j][1]);
cnt1[i][0] = cnt2[j][0] = cnt1[i][1] = cnt2[j][1] = 0;
j ++, ans += step1 + step2;
}else{
cnt2[j][(s2[p[j][1] - 1] - '0')] --;
int step1 = min(cnt1[i][0], cnt2[j][0]), step2 = min(cnt1[i][1], cnt2[j][1]);
cnt1[i][0] -= step1, cnt2[j][0] -= step1, cnt1[i][1] -= step2, cnt2[j][1] -= step2;
if(cnt1[i][0]) cnt2[j][1] -= cnt1[i][0], cnt1[i][0] = 0;
if(cnt1[i][1]) cnt2[j][0] -= cnt1[i][1], cnt1[i][1] = 0;
ans += step1 + step2, cnt2[j][(s2[p[j][1] - 1] - '0')] ++;
}
}
cout<<ans<<'\n';
}
return 0;
}