#include<bits/stdc++.h>
namespace A {
	const int N = 1e5 + 5;
	int t, n;
	char s1[N], s2[N], t1[N], t2[N];
	struct Pack {
		int count0, count1;
		inline bool centre() {
			return (this->count0 == 0 && this->count1 <= 1) || (this->count0 <= 1 && this->count1 == 0);
		}
		inline bool have(const int value) {
			if (value == 0) {
				return this->count0 > 0;
			} else if (value == 1) {
				return this->count1 > 0;
			} else {
				return false;
			}
		}
		inline int get_have() {
			if (this->count0 > 0) {
				return 0;
			} else if (this->count1 > 0) {
				return 1;
			} else {
				return -1;
			}
		}
		inline void remove_have() {
			if (this->count0 > 0) {
				this->count0--;
			} else if (this->count1 > 0) {
				this->count1--;
			}
		}
		inline void remove_have(const int value) {
			if (value == 0) {
				if (this->count0 > 0) {
					this->count0--;
				}
			} else if (value == 1) {
				if (this->count1 > 0) {
					this->count1--;
				}
			}
		}
	} *p1[N], *p2[N];
	inline void solve_A() {
		for (int i = 0; i < n; i++) {
			if (t1[i] == '0' || i == 0 || t1[i] != t1[i - 1]) {
				p1[i] = new Pack;
				if (s1[i] == '0') {
					*p1[i] = {1, 0};
				} else {
					*p1[i] = {0, 1};
				}
			} else {
				p1[i] = p1[i - 1];
				if (s1[i] == '0') {
					p1[i]->count0++;
				} else {
					p1[i]->count1++;
				}
			}
			if (t2[i] == '0' || i == 0 || t2[i] != t2[i - 1]) {
				p2[i] = new Pack;
				if (s2[i] == '0') {
					*p2[i] = {1, 0};
				} else {
					*p2[i] = {0, 1};
				}
			} else {
				p2[i] = p2[i - 1];
				if (s2[i] == '0') {
					p2[i]->count0++;
				} else {
					p2[i]->count1++;
				}
			}
		}
		bool vis[N] = {};
		int result = 0;
		for (int i = 0; i < n; i++) {
//			std::printf("p1[%d]:[%d, %d] p2[%d]:[%d, %d]\n", i, p1[i]->count0, p1[i]->count1, i, p2[i]->count0, p2[i]->count1);
			if (p1[i]->centre()) {
//				std::printf("p1[%d] is centre\n", i); 
				if (p2[i]->centre()) {
//					std::printf("p2[%d] is centre\n", i); 
					result += p1[i]->get_have() == p2[i]->get_have();
					p1[i]->remove_have();
					p2[i]->remove_have();
				} else {
					if (p2[i]->have(p1[i]->get_have())) {
						p2[i]->remove_have(p1[i]->get_have());
						p1[i]->remove_have();
						result++;
					} else {
						p1[i]->remove_have();
						p2[i]->remove_have();
					}
				}
				vis[i] = true;
			} else if (p2[i]->centre()) {
//				std::printf("p2[%d] is centre\n", i); 
				if (p1[i]->have(p2[i]->get_have())) {
					p1[i]->remove_have(p2[i]->get_have());
					p2[i]->remove_have();
					result++;
				} else {
					p1[i]->remove_have();
					p2[i]->remove_have();
				}
				vis[i] = true;
			}
		}
		for (int i = 0; i < n; i++) {
			if (!vis[i]) {
//				std::printf("p1[%d]:[%d, %d] p2[%d]:[%d, %d]\n", i, p1[i]->count0, p1[i]->count1, i, p2[i]->count0, p2[i]->count1);
				if (p1[i]->have(0) && p2[i]->have(0)) {
					p1[i]->remove_have(0);
					p2[i]->remove_have(0);
					result++;
				} else if (p1[i]->have(1) && p2[i]->have(1)) {
					p1[i]->remove_have(1);
					p2[i]->remove_have(1);
					result++;
				} else {
					p1[i]->remove_have();
					p2[i]->remove_have();
				}
			}
		}
		std::cout << result << "\n";
		delete p1[0];
		delete p2[0];
		for (int i = 1; i < n; i++) {
			if (p1[i] != p1[i - 1]) {
				delete p1[i];
			}
			if (p2[i] != p2[i - 1]) {
				delete p2[i];
			}
		}
	}
	int main() {
		std::freopen("edit.in", "r", stdin);
		std::freopen("edit.out", "w", stdout);
		std::ios::sync_with_stdio(false);
		std::cin.tie(nullptr);
		std::cout.tie(nullptr);
		for (std::cin >> t; t; t--) {
			std::cin >> n >> s1 >> s2 >> t1 >> t2;
			solve_A();
		}
		return 0;
	}
}
int main()
{
	return A::main();
}
