#include<iostream>
#include<queue>
#include<cmath> 
#define int long long
using namespace std;
queue<int> qu1;
queue<int> qu2;
signed main(){
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	int t;
	cin>>t;
	while(t--){
		int n;
		bool f = 0; 
		cin>>n;
		string a,b;
		cin>>a>>b;
		string t1,t2;
		cin>>t1>>t2;
		int k1 = n - 1;
		int k2 = n - 1;
		int l = 0,ans = 0;
		for(int i=0;i<n;i++){
			if(t1[i]=='0'){
				qu1.push(i);
			}
			if(t2[i]=='0'){
				qu2.push(i);
			}
		}
		qu1.push(n-1);
		qu2.push(n-1); 
		int last = 0;
		int cnt1 = 0;
		int cnt2 = 0;
		while(!qu1.empty()&&!qu2.empty()&&l<n){
			int x = qu1.front();
			int y = qu2.front();
			if(last != x){
				for(int i=l;i<x;i++){
					if(a[i]=='1'){
						cnt1++;
					}
				}			
			}
			if(last != y){
				for(int i=l;i<y;i++){
					if(b[i] == '1'){
						cnt2++;
					}
				}	
			} 
			if(x==y){
				if(b[y] == '1')cnt2++;
				qu2.pop();
				qu1.pop();
				ans+= x - l + 1 - abs(cnt1 - cnt2);
				cnt1 = 0;
				cnt2 = 0;
				l = x + 1;
			}
			if(x>y){
				f = 1;
				if(b[y] == '1')cnt2++;
				qu2.pop();
				last = x;
	
				if(cnt1<cnt2){
					ans+=cnt1;
					ans+=min(x-l+1-cnt2,x-l+1-cnt1);
					cnt1=0;
				}
				if(cnt1>=cnt2){
					ans+=cnt2;
					cnt1-=cnt2;
					ans+=min(y-l+1-cnt2,x-l+1-cnt1);
				}
				cnt2=0;
				l = y + 1;
			}
			if(x<y){
				f = 1;
				if(a[x]=='1')cnt1++;
				qu1.pop();
				last = y;
				if(cnt2<cnt1){
					ans+=cnt2;
					ans+=min(x-l+1-cnt2,x-l+1-cnt1);
					cnt2=0;
				}
				if(cnt2>=cnt1){
					ans+=cnt1;
					cnt2-=cnt1;
					ans+=min(y-l+1-cnt2,x-l+1-cnt1);
				}
				cnt1=0;
				l = x + 1;
			}
		}
		if(f){	
			cout<<ans - 2<<endl;
		}
		else{
			cout<<ans;
		}
	}
	return 0;
}
