#include<bits/stdc++.h>
#define sf scanf
#define pf printf
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define per(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
typedef long long ll;
namespace abcdefg {
	constexpr int N=1e5+7;
    int t,n;
    char a[N],b[N],ta[N],tb[N];
    int ans;
    int cnta[2],cntb[2];
	void main() {
		sf("%d",&t);
        while(t--) {
            sf("%d",&n);
            ans=0;
            cnta[0]=cnta[1]=cntb[0]=cntb[1]=0;
            sf("%s%s%s%s",a+1,b+1,ta+1,tb+1);
            // int cnt=0;
            // rep(i,1,333) if(b[i]=='1')++cnt;
            // pf("%d\n",cnt);
            int k=0;
            int ita=0,itb=0;
            rep(i,1,n) {
                ++k;
                if(ita<i) {
                    if(ta[i]=='0') cnta[0]=cnta[1]=0,cnta[a[i]-'0']++,++ita;
                    else while(ita<n && ta[ita+1]=='1') ++ita, cnta[a[ita]-'0']++;
                }
                if(itb<i) {
                    if(tb[i]=='0') cntb[0]=cntb[1]=0,cntb[b[i]-'0']++,++itb;
                    else while(itb<n && tb[itb+1]=='1') ++itb, cntb[b[itb]-'0']++;
                }
                while(cnta[0]&&cntb[0]&&k) --cnta[0],--cntb[0],++ans,--k;
                while(cnta[1]&&cntb[1]&&k) --cnta[1],--cntb[1],++ans,--k;
                if(ta[i]=='0') cnta[0]=cnta[1]=0,k=0;
                if(tb[i]=='0') cntb[0]=cntb[1]=0,k=0;
                // pf("%d %d %d %d %d\n",cnta[0],cnta[1],cntb[0],cntb[1],ans);
            }
            pf("%d\n",ans);
        }
	}
}
int main() {
	#ifdef LOCAL
	freopen("my.out","w",stdout);
	#else 
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	#endif
	abcdefg :: main();
}