#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen("edit.in","r",stdin);
//	freopen("edit.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T,len,ans,cnt1,cnt2,indx;
	string s1,s2,t1,t2;
	cin>>T;
	while(T--){
		indx=0;
		ans=0;
		cnt1=0;
		cnt2=0;
		cin>>len>>s1>>s2>>t1>>t2;
		for(int i=0;i<len;i++){
			if(t1[i]=='0'){
//				cout<<ans<<"   ";
				ans+=min(cnt1,cnt2);
//				cout<<ans<<"   ";
				ans+=indx-max(cnt1,cnt2);
//				cout<<ans<<'\n';
				if(s1[i]==s2[i]){
					ans++;
				}
				cnt1=0;
				cnt2=0;
				indx=0;
				continue;
			}
			if(s1[i]=='1'){
				cnt1++;
			}
			if(s2[i]=='1'){
				cnt2++;
			}
			indx++;
		}
		ans+=min(cnt1,cnt2);
		ans+=indx-max(cnt1,cnt2);
		cout<<ans<<'\n';
	}
	return 0;
}
