#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
string s,t,qs,qt;
int n,ans;
int lst[N],q[N],sta[N][2],top1,top0;
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;
	cin >> T;
	while(T--){
		cin >> n;
		cin >> s >> t >> qs >> qt;
		s = "$" + s;
		t = "$" + t;
		ans = 0;
		top1 = 0;
		top0 = 0;
		memset(sta,0,sizeof(sta));
		memset(lst,0,sizeof(lst));
		memset(q,0,sizeof(q));
		qs = "$" + qs;
		qt = "$" + qt;
		for(int i = 1; i <= n; ++i) q[i] = qs[i] - '0';
		for(int i = 2; i <= n; ++i){
			if(qt[i] == '1' && qt[i-1] == '1'){
				q[i] = (q[i]|1);
				q[i-1] = (q[i-1]|1);
			}
		}
		int ls = 114514;
		for(int i = 1; i <= n; ++i){
			if(q[i] == 1 && ls == 114514 && q[i+1] == 1 && i + 1 != n){
				lst[i] = i;
				ls = i;
			}else if(q[i] != q[i-1]) ls = 114514;
			else lst[i] = ls;
		}
		for(int i = 1; i <= n; ++i){
			if(s[i] == t[i]) ++ans;
			else{
				if(q[i] == 0){
					top1 = 0;
					top0 = 0;
					continue;
				}
				if(s[i] == '1'){
					if(!top1 || !top0){
						sta[++top1][1] = i;
						continue;
					} 
					if(lst[i] == lst[sta[top0][0]]){
						ans += 2;
						top0--;
					}else{
						top0 = 0;
						top1 = 0;
					}
				}else{
					if(!top0 || !top1){
						sta[++top0][0] = i;
						continue;
					} 
					if(lst[i] == lst[sta[top1][1]]){
						ans += 2;
						top1--;
					}else{
						top1 = 0;
						top0 = 0;
					} 		
				}
			}
		}
		//cout << top0 << " " << top1 << "\n";
		ans = ans + min(top0,top1) * 2;
		cout << ans << "\n";
	}
	return 0;
}
