#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;

typedef unsigned long long qword;
typedef unsigned int       dword;
typedef long long          int64;

#define rep(lt, rt, vrb) for (dword vrb = lt; vrb <= rt; vrb++)
#define trv(poitype, begin, end, poi) for (poitype poi = begin; poi != end; poi++)
#define HEAD 1

namespace FastIO {
	template<typename Type>
	inline void read(Type &vrb) {
		static char c = getchar();
		bool neg = false;
		while ('0' > c || c > '9') {
			if (c == '-')
				neg = true;
			c = getchar();
		}
		vrb = 0;
		while ('0' <= c && c <= '9') {
			vrb = (vrb << 3) + (vrb << 1) + (c - '0');
			c = getchar();
		}
		if (neg)
			vrb = -vrb;
	}
	
	inline void read(char *str) {
		static char c = getchar();
		while ('0' > c || c > '1') 
			c = getchar();
		while ('0' <= c && c <= '1') {
			*str = c;
			str++;
			c = getchar();
		}
		*str = '\0';
	}
	
	template<typename Type>
	void write(Type vrb, const char end = '\n') {
		if (vrb < 0) {
			putchar('-');
			vrb = -vrb;
		}
		if (vrb > 9)
			write(vrb / 10, '\0');
		putchar((vrb % 10) + '0');
		if (end)
			putchar(end);
	}
	
	template<typename Type>
	void write(Type arr[], const dword len, const char sep = ' ', const char end = '\n') {
		rep(HEAD, len, i)
			write(arr[i], sep);
		if (end)
			putchar(end); 
	}
	
	void write(char *str) {
		while (*str) {
			putchar(*str);
			str++;
		}
	}
	
	void write(const char *str) {
		while (*str) {
			putchar(*str);
			str++;
		}
	}
}

struct Bds {
	dword lt, rt;
	dword cnt_0, cnt_1;
	Bds(const dword _lt) {
		lt = _lt;
		rt = _lt;
		cnt_0 = 0, cnt_1 = 0;
	}
};


// def mem
const dword MAXN = 1.5e5;
dword T;
dword n;
char s_1[MAXN], s_2[MAXN], t_1[MAXN], t_2[MAXN];
deque<Bds> bds_1, bds_2;
dword ans;


int main() {
	freopen("edit.in", "r", stdin);
	freopen("edit.out", "w", stdout);
	using namespace FastIO;
	read(T);
	while (T--) {
		// in
		read(n);
		read(s_1);
		read(s_2);
		read(t_1);
		read(t_2);
		
		// opt
		for (dword i = 0; i < n; i++) {
			if (t_1[i] == '1') {
				bds_1.push_back(Bds(i));
				while (i < n && t_1[i] == '1') {
					bds_1.back().rt++;
					if (s_1[i] == '0')
						bds_1.back().cnt_0++;
					else
						bds_1.back().cnt_1++;
					i++;
				}
				bds_1.back().rt--;
			}
		}
		for (dword i = 0; i < n; i++) {
			if (t_2[i] == '1') {
				bds_2.push_back(Bds(i));
				while (i < n && t_2[i] == '1') {
					bds_2.back().rt++;
					if (s_2[i] == '0')
						bds_2.back().cnt_0++;
					else
						bds_2.back().cnt_1++;
					i++;
				}
				bds_2.back().rt--;
			}
		}
		ans = 0;
		for (dword i = 0; i < n; i++) {
			if (t_1[i] == '0' && t_2[i] == '0' && s_1[i] == s_2[i])
				ans++;
			else if (t_1[i] == '1' && t_2[i] == '0') {
				while (i < n && t_1[i] == '1' && t_2[i] == '0') {
					if (s_2[i] == '1' && bds_1.front().cnt_1) {
						bds_1.front().cnt_1--;
						ans++;
					}
					if (s_2[i] == '0' && bds_1.front().cnt_0) {
						bds_1.front().cnt_0--;
						ans++;
					}
					i++;
				}
				i--;
			} else if (t_1[i] == '0' && t_2[i] == '1') {
				while (i < n && t_1[i] == '0' && t_2[i] == '1') {
					if (s_1[i] == '1' && bds_2.front().cnt_1) {
						bds_2.front().cnt_1--;
						ans++;
					}
					if (s_1[i] == '0' && bds_2.front().cnt_0) {
						bds_2.front().cnt_0--;
						ans++;
					}
					i++;
				}
				i--;
			} else if (t_1[i] == '1' && t_2[i] == '1') {
				if (bds_1.front().rt == bds_2.front().rt) {
					ans += min(bds_1.front().cnt_1, bds_2.front().cnt_1);
					ans += min(bds_1.front().cnt_0, bds_2.front().cnt_0);
					
					i = bds_1.front().rt;
				} else if (bds_1.front().rt < bds_2.front().rt) {
					if (bds_2.front().cnt_0 > bds_1.front().cnt_0) {
						ans += bds_1.front().cnt_0;
						bds_2.front().cnt_0 -= bds_1.front().cnt_0;
					} else {
						ans += bds_2.front().cnt_0;
						bds_2.front().cnt_0 = 0; 
					}
					if (bds_2.front().cnt_1 > bds_1.front().cnt_1) {
						ans += bds_1.front().cnt_1;
						bds_2.front().cnt_1 -= bds_1.front().cnt_1;
					} else {
						ans += bds_2.front().cnt_1;
						bds_2.front().cnt_1 = 0; 
					}
					
					i = bds_1.front().rt;
				} else if (bds_1.front().rt > bds_2.front().rt) {
					if (bds_1.front().cnt_0 > bds_2.front().cnt_0) {
						ans += bds_2.front().cnt_0;
						bds_1.front().cnt_0 -= bds_2.front().cnt_0;
					} else {
						ans += bds_1.front().cnt_0;
						bds_1.front().cnt_0 = 0;
					}
					if (bds_1.front().cnt_1 > bds_2.front().cnt_1) {
						ans += bds_2.front().cnt_1;
						bds_1.front().cnt_1 -= bds_2.front().cnt_1;
					} else {
						ans += bds_1.front().cnt_1;
						bds_1.front().cnt_1 = 0; 
					}
					
					i = bds_2.front().rt;
				}
			}
			if (!bds_1.empty() && i >= bds_1.front().rt)
				bds_1.pop_front();
			if (!bds_2.empty() && i >= bds_2.front().rt)
				bds_2.pop_front();
		}
		
		// out
		write(ans);
		
	}
	return 0;
}

