#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; 
namespace fastio{
	template<typename T> inline void read(T &t){
		T x = 0, f = 1;
		char c = getchar();
		while(!isdigit(c)){
			if(c == '-') f = -f;
			c = getchar();
		}
		while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
		t = x * f;
	}
	template<typename T, typename ... Args> inline void read(T &t, Args &...args){
		read(t), read(args...);
	}
}
using namespace fastio;
#define multitest() int T; read(T); for(int tCase = 1; tCase <= T; ++tCase)
const int N = 1e5 + 5;
int n;
char s1[N], s2[N], t1[N], t2[N];
struct dsu{
	int fa[N], cnt[N][2];
	void init(char *s){_rep(i, 1, n) fa[i] = i, cnt[i][s[i] - '0']++;}
	int find(int x){
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	void merge(int x, int y){
		int fx = find(x), fy = find(y);
		if(fx != fy) fa[fx] = fy, cnt[fy][0] += cnt[fx][0], cnt[fy][1] += cnt[fx][1];
	}
	void clr(){
		_rep(i, 1, n) fa[i] = 0, cnt[i][0] = cnt[i][1] = 0;
	}
}f, g;
int main(){
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	multitest(){
		read(n);
		scanf("%s%s%s%s", s1 + 1, s2 + 1, t1 + 1, t2 + 1);
		int ans = 0;
		f.init(s1), g.init(s2);
		_rep(i, 2, n){
			if(t1[i] == '1' && t1[i - 1] == '1') f.merge(i, i - 1);
			if(t2[i] == '1' && t2[i - 1] == '1') g.merge(i, i - 1);
		}
		_rep(i, 1, n){
			int x = f.find(i), y = g.find(i);
			if(f.cnt[x][0] && g.cnt[y][0]){
				ans++, f.cnt[x][0]--, g.cnt[y][0]--;
			}else if(f.cnt[x][1] && g.cnt[y][1]){
				ans++, f.cnt[x][1]--, g.cnt[y][1]--;
			}
		}
		printf("%d\n", ans);
		f.clr(), g.clr();
	}	
	return 0;
}
/*
1
6
011101
111010
111010
101101

*/
