#include<bits/stdc++.h>
using namespace std;
namespace my_std{
	#define ll long long
	#define bl bool
	#define fr(i,x,y) for(ll i=(x);i<=(y);i++)
	#define pfr(i,x,y) for(ll i=(x);i>=(y);i--)
	#define go(u) for(ll i=head[u];i;i=e[i].nxt)
	#define il inline
	#define db double
	#define pf printf
	#define pc putchar
	#define MP make_pair
	#define fir first
	#define sec second
	#define space pc(' ')
	#define enter pc('\n')
	il ll read(){
		ll sum=0,fu=0;
		char ch=getchar();
		while(!isdigit(ch)){
			if(ch=='-') fu=1;
			ch=getchar();
		}
		while(isdigit(ch)){
			sum=sum*10+(ch-'0');
			ch=getchar();
		}
		return fu?(-sum):sum;
	}
	void write(ll x){
		if(x<0){
			pc('-');
			x=-x;
		}
		if(x>9) write(x/10);
		pc('0'+(x%10));
	}
	il void writesp(ll x){
		write(x);
		space;
	}
	il void writeln(ll x){
		write(x);
		enter;
	}
}
using namespace my_std;
ll T,n,ans=0;
char s[2][100010],t[2][100010];
int main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	T=read();
	while(T--){
		n=read();
		scanf("%s",s[0]+1);
		scanf("%s",s[1]+1);
		scanf("%s",t[0]+1);
		scanf("%s",t[1]+1);
		ll lst=0,pos=1,cnt0=0,cnt1=0,o=0;
		fr(i,1,n){
			if(t[0][i]=='0') break;
			if(s[0][i]=='0') cnt0++;
			else cnt1++;
		}
		while(1){
			while(pos<=n&&t[0][pos]=='1'&&t[1][pos]=='1') pos++;
			ll x=0,y=0;
			fr(i,lst+1,n){
				if(t[o^1][i]=='0') break;
				if(s[o^1][i]=='0') x++;
				else y++;
			}
			if(pos>n||(t[0][pos]=='0'&&t[1][pos]=='0')){
				ans+=min(cnt0,x)+min(cnt1,y);
				if(pos<=n&&s[0][pos]==s[1][pos]) ans++;
				if(pos>n) break;
				o=0;
				cnt0=cnt1=0;
				fr(i,pos+1,n){
					if(t[0][i]=='0') break;
					if(s[0][i]=='0') cnt0++;
					else cnt1++;
				}
			}
			else if(t[o][pos]=='0'){
				if(s[o][pos]=='0') cnt0++;
				else cnt1++;
				ans+=min(cnt0,x)+min(cnt1,y);
				o^=1;
				if(x<cnt0){
					cnt1=x+y-cnt0-cnt1;
					cnt0=0;
				}
				else if(y<cnt1){
					cnt0=x+y-cnt0-cnt1;
					cnt1=0;
				}
				else{
					cnt0=x-cnt0;
					cnt1=y-cnt1;
				}
			}
			else{
				if(s[o^1][pos]=='0') x++;
				else y++;
				ans+=min(cnt0,x)+min(cnt1,y);
				if(cnt0<x){
					cnt1=cnt0+cnt1-x-y;
					cnt0=0;
				}
				else if(cnt1<y){
					cnt0=cnt0+cnt1-x-y;
					cnt1=0;
				}
				else{
					cnt0-=x;
					cnt1-=y;
				}
			}
			lst=pos;
			pos=lst+1;
		}
		writeln(ans);
		ans=0;
	}
}
