#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
const int N = 1e5 + 7;

typedef long long ll;
typedef pair<int,int> pii;

int n,ans;
string ori,trg;
string och,tch;
vector <pii> obr,tbr;
vector <pii> ocnt,tcnt;//cnt of 0 / 1;
int oidx,tidx;
void oper(){
//	cout << endl;
//	cout << oidx << " " << tidx << endl;
//	cout << ocnt[oidx].x << " " << ocnt[tidx].y << " " << tcnt[oidx].x << " " << tcnt[tidx].y << endl;
	
	ans += min(ocnt[oidx].x,tcnt[tidx].x) + min(ocnt[oidx].y,tcnt[tidx].y);
	
	int olen = obr[oidx].y - obr[oidx].x + 1,tlen = tbr[tidx].y - tbr[tidx].x + 1;
	if(olen > tlen){
		int cnt0 = ocnt[oidx].x - tcnt[tidx].x,cnt1 = ocnt[oidx].y - tcnt[tidx].y;
		if(cnt0 < 0) cnt1 += cnt0,cnt0 = 0;
		if(cnt1 < 0) cnt0 += cnt1,cnt1 = 0;
		ocnt[oidx] = {cnt0,cnt1},obr[oidx] = {tbr[tidx].y + 1,obr[oidx].y},tidx++;
//		cout << "o_change :" << cnt0 << " " << cnt1 << endl;
	}
	else if(olen < tlen){
		int cnt0 = tcnt[tidx].x - ocnt[oidx].x,cnt1 = tcnt[tidx].y - ocnt[oidx].y;
		if(cnt0 < 0) cnt1 += cnt0,cnt0 = 0;
		if(cnt1 < 0) cnt0 += cnt1,cnt1 = 0;
		tcnt[tidx] = {cnt0,cnt1},tbr[tidx] = {obr[oidx].y + 1,tbr[tidx].y},oidx++;
//		cout << "t_change :" << cnt0 << " " << cnt1 << endl;
	}
	else{
		oidx++,tidx++;
//		cout << "push\n";
	}
	
//	cout << endl;
}
void work(){
	cin >> n,ans = 0;
	cin >> ori >> trg;
	cin >> och >> tch;
	ori = " " + ori,trg = " " + trg;
	och = " " + och,tch = " " + tch;
	obr.clear(),tbr.clear(),ocnt.clear(),tcnt.clear();
	
	int pre = 1;
	for(int i = 1;i <= n;)
		if(och[i] == '1'){
			while(och[i] == '1' && i <= n) i++;
			obr.push_back({pre,i - 1});
			pre = i;
		}
		else if(och[i] == '0'){
			if(i <= n) i++,obr.push_back({pre,i - 1});
			pre = i;
		}
		
	pre = 1;
	for(int i = 1;i <= n;)
		if(tch[i] == '1'){
			while(tch[i] == '1' && i <= n) i++;
			tbr.push_back({pre,i - 1});
			pre = i;
		}
		else if(tch[i] == '0'){
			if(i <= n) i++,tbr.push_back({pre,i - 1});
			pre = i;
		}
	
	int cnt0,cnt1;
	for(auto i : obr){
		cnt0 = 0,cnt1 = 0;
		for(int j = i.x;j <= i.y;j++) 
			if(ori[j] == '0') cnt0++;
			else cnt1++;
		ocnt.push_back({cnt0,cnt1});
	}
	for(auto i : tbr){
		cnt0 = 0,cnt1 = 0;
		for(int j = i.x;j <= i.y;j++) 
			if(trg[j] == '0') cnt0++;
			else cnt1++;
		tcnt.push_back({cnt0,cnt1});
	}

	oidx = 0,tidx = 0;
	while(oidx < (int)obr.size() && tidx < (int)tbr.size()) oper();
	
	cout << ans << endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	
	freopen("edit.in","r",stdin);
	freopen("edit.out","w",stdout);
	
	int _;cin >> _;
	while(_--) work();
	
	flush(cout);
	fclose(stdin),fclose(stdout); 
	
	return 0;
}
//done. 

