There is a chessboard of size $n$ by $n$. The square in the $i$-th row from top and $j$-th column from the left is labelled $(i,j)$.

Currently, Gregor has some pawns in the $n$-th row. There are also enemy pawns in the $1$-st row. On one turn, Gregor moves one of his pawns. A pawn can move one square up (from $(i,j)$ to $(i-1,j)$) if there is no pawn in the destination square. Additionally, a pawn can move one square diagonally up (from $(i,j)$ to either $(i-1,j-1)$ or $(i-1,j+1)$) if and only if there is an enemy pawn in that square. The enemy pawn is also removed.

Gregor wants to know what is the maximum number of his pawns that can reach row $1$?

Note that only Gregor takes turns in this game, and the enemy pawns never move. Also, when Gregor's pawn reaches row $1$, it is stuck and cannot make any further moves.


-----Input-----

The first line of the input contains one integer $t$ ($1\le t\le 2\cdot 10^4$) — the number of test cases. Then $t$ test cases follow.

Each test case consists of three lines. The first line contains a single integer $n$ ($2\le n\le 2\cdot{10}^{5}$) — the size of the chessboard.

The second line consists of a string of binary digits of length $n$, where a $1$ in the $i$-th position corresponds to an enemy pawn in the $i$-th cell from the left, and $0$ corresponds to an empty cell.

The third line consists of a string of binary digits of length $n$, where a $1$ in the $i$-th position corresponds to a Gregor's pawn in the $i$-th cell from the left, and $0$ corresponds to an empty cell.

It is guaranteed that the sum of $n$ across all test cases is less than $2\cdot{10}^{5}$.


-----Output-----

For each test case, print one integer: the maximum number of Gregor's pawns which can reach the $1$-st row.


-----Examples-----

Input
4
3
000
111
4
1111
1111
3
010
010
5
11001
00000
Output
3
4
0
0


-----Note-----

In the first example, Gregor can simply advance all $3$ of his pawns forward. Thus, the answer is $3$.

In the second example, Gregor can guarantee that all $4$ of his pawns reach the enemy row, by following the colored paths as demonstrated in the diagram below. Remember, only Gregor takes turns in this "game"!

In the third example, Gregor's only pawn is stuck behind the enemy pawn, and cannot reach the end.

In the fourth example, Gregor has no pawns, so the answer is clearly $0$.

Source: codeforces | Difficulty: EASY
Tags: Graph algorithms

Graph traversal

Implementation

Greedy algorithms

Dynamic programming

Flows and cuts


Solutions:
entrada = int(input())
for i in range(entrada):
	n = int(input())
	s = list(input())
	l = list(input())
	count = 0
	for i in range(n):
		if l[i] == '1':
			if s[i] == '0':
				count += 1
			elif i != 0 and s[i - 1] == '1':
				s[i - 1] = '0'
				count += 1
			elif i != n - 1 and s[i + 1] == '1':
				s[i + 1] = '0'
				count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	enemey = list(input())
	gregor = list(input())
	pawns = 0
	for i in range(n):
		if gregor[i] == '1':
			if enemey[i] == '0':
				enemey[i] = '2'
				pawns += 1
			elif i == 0 and enemey[i + 1] == '1':
				enemey[i + 1] = '2'
				pawns += 1
				continue
			elif i == n - 1 and enemey[i - 1] == '1':
				enemey[i - 1] = '2'
				pawns += 1
				continue
			elif i != 0 and i != n - 1:
				if enemey[i - 1] == '1':
					enemey[i - 1] = '2'
					pawns += 1
					continue
				elif enemey[i + 1] == '1':
					enemey[i + 1] = '2'
					pawns += 1
	print(pawns)


res = ''
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	ans = 0
	for (i, pawn) in enumerate(b):
		if pawn == '0':
			continue
		if a[i] == '0':
			ans += 1
			a[i] = '1m'
			b[i] = '0'
		elif n == 1:
			break
		elif i == 0:
			if a[1] == '1':
				ans += 1
				b[i] = '0'
				a[1] = '1m'
		elif i == n - 1:
			if a[n - 2] == '1':
				ans += 1
				b[n - 1] = '0'
				a[n - 1] = '1m'
		elif a[i - 1] == '1':
			b[i] = '0'
			ans += 1
			a[i - 1] = '1m'
		elif a[i + 1] == '1':
			b[i] = '0'
			a[i + 1] = '1m'
			ans += 1
	res += '%d\n' % ans
print(res)


import os, sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	enemy = list(input())
	me = list(input())
	count = 0
	i = 0
	while i < n:
		if i == 0:
			if me[i] == '1':
				if enemy[i] == '0':
					enemy[i] = 'X'
					count += 1
				elif i + 1 < n and enemy[i + 1] == '1':
					enemy[i + 1] = 'X'
					count += 1
		elif me[i] == '1':
			if i - 1 >= 0 and enemy[i - 1] == '1':
				enemy[i - 1] = 'X'
				count += 1
			elif enemy[i] == '0':
				enemy[i] = 'X'
				count += 1
			elif i + 1 < n and enemy[i + 1] == '1':
				enemy[i + 1] = 'X'
				count += 1
		i += 1
	print(count)


from typing import Counter
t = int(input())
for j in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	count = 0
	for position in range(n):
		if b[position] == '1':
			if a[position] == '0':
				count += 1
			elif position != 0 and position != n - 1:
				if a[position - 1] == '1':
					a[position - 1] = '0'
					count += 1
				elif a[position + 1] == '1':
					a[position + 1] = '0'
					count += 1
			elif position == 0:
				if a[position + 1] == '1':
					a[position + 1] = '0'
					count += 1
			elif a[position - 1] == '1':
				a[position - 1] = '0'
				count += 1
	print(count)


test_num = int(input())
tests = []
answers = []
for i in range(test_num):
	tests.append((int(input()), list(input()), list(input())))

def find_answer(n, enemy, army):
	demand = []
	for i in range(n):
		demand.append(0)
	for i in range(n):
		if army[i] != '0':
			if i - 1 >= 0 and enemy[i - 1] == '1':
				demand[i - 1] += 2
				enemy[i - 1] = '2'
			elif enemy[i] == '0':
				demand[i] += 2
				enemy[i] = '2'
			elif i + 1 < n and enemy[i + 1] == '1':
				demand[i + 1] += 2
				enemy[i + 1] = '2'
	return demand.count(2)
for i in range(test_num):
	answers.append(find_answer(tests[i][0], tests[i][1], tests[i][2]))
for i in range(test_num):
	print(answers[i])


t = int(input())
for _ in range(t):
	n = int(input())
	first = input()
	last = input()
	visited = [True] * n
	count = 0
	for i in range(n):
		if last[i] == '1':
			if first[i] == '0':
				count += 1
				visited[i] = True
			elif first[i] == '1':
				if i > 0 and first[i - 1] == '1' and visited[i - 1]:
					count += 1
					visited[i - 1] = False
				elif i < n - 1 and first[i + 1] == '1' and visited[i + 1]:
					count += 1
					visited[i + 1] = False
	print(count)


t = int(input())
for _ in range(t):
	n = int(input())
	enemy = list(input().strip())
	friend = list(input().strip())
	k = 0
	for i in range(n):
		if friend[i] == '1':
			if enemy[i] != '1':
				k += 1
			elif i != 0 and enemy[i - 1] == '1':
				enemy[i - 1] = '0'
				k += 1
			elif i != n - 1 and enemy[i + 1] == '1':
				enemy[i + 1] = '0'
				k += 1
	print(k)


t = int(input())
for tc in range(t):
	n = int(input())
	r1 = list(input())
	rn = list(input())
	if '1' not in rn:
		print(0)
		continue
	if '1' not in r1:
		print(rn.count('1'))
		continue
	res = 0
	for i in range(n):
		if rn[i] == '1':
			if i != 0 and i != n - 1:
				if r1[i - 1] == '1':
					res += 1
					r1[i - 1] = '2'
				elif r1[i] == '0':
					res += 1
				elif r1[i + 1] == '1':
					res += 1
					r1[i + 1] = '2'
			elif i == 0:
				if r1[i] == '0':
					res += 1
				elif r1[i + 1] == '1':
					res += 1
					r1[i + 1] = '2'
			elif i == n - 1:
				if r1[i - 1] == '1':
					res += 1
					r1[i - 1] = '2'
				elif r1[i] == '0':
					res += 1
	print(res)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def output_list(l):
	print(' '.join(list(map(str, l))))

class Node:

	def __init__(self, i, next):
		self.i = i
		self.next = next

	def __str__(self):
		return str(self.i)

def test_case():
	n = inp()
	enemy = list(input().strip())
	gregor = list(input().strip())
	max_advances = 0
	for i in range(n):
		if int(gregor[i]) == 1:
			if int(enemy[i]) == 0:
				max_advances += 1
				enemy[i] == '2'
			elif i - 1 >= 0 and int(enemy[i - 1]) == 1:
				max_advances += 1
				enemy[i - 1] = '2'
			elif i + 1 < n and int(enemy[i + 1]) == 1:
				max_advances += 1
				enemy[i + 1] = '2'
	print(max_advances)
n_cases = inp()
for i in range(n_cases):
	test_case()


import sys
input = lambda : sys.stdin.readline().rstrip()

def solve_tc():
	n = int(input())
	s2 = [-1] + list(map(int, list(input())))
	s1 = list(map(int, list(input())))
	s2.append(-1)
	ans = 0
	for i in range(len(s1)):
		if s1[i] == 1:
			if s2[i] == 1:
				ans += 1
			elif s2[i + 1] == 0:
				s2[i + 1] = -1
				ans += 1
			elif s2[i + 2] == 1:
				ans += 1
				s2[i + 2] = -1
	return ans
t = int(input())
for _ in range(t):
	sys.stdout.write(str(solve_tc()) + '\n')


t = int(input())

def greedy(enemy: list, me: list):
	ans = 0
	for i in range(len(me)):
		if me[i] == '1' and enemy[i] == '0':
			me[i] = '0'
			enemy[i] = '2'
			ans += 1
	for i in range(len(me)):
		if me[i] == '0':
			continue
		if i - 1 >= 0 and enemy[i - 1] == '1':
			enemy[i - 1] = '2'
			me[i] = '0'
			ans += 1
		elif i + 1 < len(me) and enemy[i + 1] == '1':
			enemy[i + 1] = '2'
			me[i] = '0'
			ans += 1
	return ans
for _ in range(t):
	sz = int(input())
	enemy = input()
	me = input()
	print(greedy(list(enemy), list(me)))


import collections
from collections import defaultdict
import math
from math import factorial
from math import gcd
from collections import Counter
for t in range(int(input())):
	n = int(input())
	opp = ['o' if x == '1' else '0' for x in input()]
	pawn = ['p' if x == '1' else '0' for x in input()]
	ans = 0
	for i in range(n):
		if pawn[i] == 'p':
			if opp[i] == '0':
				opp[i] = 'p'
				ans += 1
			elif i > 0 and opp[i - 1] == 'o':
				opp[i - 1] = 'p'
			elif i < n - 1 and opp[i + 1] == 'o':
				opp[i + 1] = 'p'
	print(opp.count('p'))


def solve(n, enemy, gregory):
	destination = [e for e in enemy]
	pieces_that_can_pass = 0
	for i in range(n):
		if gregory[i] == '0':
			continue
		if destination[i] == '0':
			pieces_that_can_pass += 1
			destination[i] = '2'
			continue
		next_indices = []
		if i > 0:
			next_indices.append(i - 1)
		if i + 1 < n:
			next_indices.append(i + 1)
		for j in next_indices:
			if destination[j] == '1':
				pieces_that_can_pass += 1
				destination[j] = '2'
				break
	return pieces_that_can_pass

def main():
	test_cases = int(input())
	for t in range(test_cases):
		n = int(input())
		enemy = input()
		gregory = input()
		a = solve(n, enemy, gregory)
		print(a)
main()


from collections import Counter, deque
from math import *
mod = 1000000007

def isPrime(n):
	if n < 2:
		return False
	if n == 2 or n == 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	for i in range(5, int(sqrt(n) + 1), 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = int(input())
	enemy = list(input())
	my = list(input())
	count = 0
	for i in range(n):
		if my[i] != '0':
			if enemy[i] == '0':
				count += 1
			elif i == 0:
				if enemy[i + 1] == '1':
					count += 1
					enemy[i + 1] = '0'
			elif i == n - 1:
				if enemy[i - 1] == '1':
					count += 1
					enemy[i - 1] = '0'
			elif enemy[i - 1] == '1':
				count += 1
				enemy[i - 1] = '0'
			elif enemy[i + 1] == '1':
				count += 1
				enemy[i + 1] = '0'
	print(count)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
while t > 0:
	n = int(input())
	enemys = str(input())
	ours = str(input())
	enemy = []
	our = []
	for i in range(n):
		enemy.append(int(enemys[i]))
		our.append(int(ours[i]))
	ep = 0
	op = 0
	ans = 0
	for i in enemy:
		if i == 1:
			ep += 1
	for i in our:
		if i == 1:
			op += 1
	if ep == 0:
		print(op)
	elif op == 0:
		print(0)
	else:
		for i in range(n):
			if enemy[i] == 0 and our[i] == 1:
				ans += 1
				our[i] = 0
		for i in range(n):
			if our[i] == 1:
				if i > 0 and enemy[i - 1] == 1:
					ans += 1
					enemy[i - 1] = 0
				elif i < n - 1 and enemy[i + 1] == 1:
					ans += 1
					enemy[i + 1] = 0
		print(ans)
	t = t - 1


def solve(n, a, b):
	ans = 0
	marked = set()
	for i in range(n):
		if a[i] == '1':
			if i > 0 and b[i - 1] == '1' and (i - 1 not in marked):
				ans += 1
			elif b[i] == '0':
				ans += 1
			elif i < n - 1 and b[i + 1] == '1' and (i + 1 not in marked):
				ans += 1
				marked.add(i + 1)
	return ans
for t in range(int(input())):
	n = int(input())
	b = input()
	a = input()
	print(solve(n, a, b))


def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		s = input()
		s = list(s)
		t = input()
		ans = 0
		for i in range(n):
			if t[i] == '0':
				continue
			if s[i] == '0':
				ans += 1
				s[i] = 'x'
			elif i > 0 and s[i - 1] == '1':
				ans += 1
				s[i - 1] = 'x'
			elif i < n - 1 and s[i + 1] == '1':
				ans += 1
				s[i + 1] = 'x'
		print(ans)
main()


def solve(n, a, b):
	if b.count('1') == 0:
		return 0
	for i in range(n):
		a[i] = [a[i], 0]
		b[i] = [b[i], 1]
	ans = 0
	for i in range(n):
		if b[i][0] == '1':
			if i > 0 and a[i - 1] == ['1', 0]:
				ans += 1
				a[i - 1] = ['1', 1]
			elif a[i] == ['0', 0]:
				ans += 1
				a[i] = ['1', 1]
			elif i < n - 1 and a[i + 1] == ['1', 0]:
				ans += 1
				a[i + 1] = ['1', 1]
	return ans
for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	print(solve(n, a, b))


from os import sep
l = []
for __ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	ans = 0
	for i in range(n):
		if t[i] == '1':
			if s[i] == '0':
				ans += 1
				s[i] = '2'
			elif i > 0 and s[i - 1] == '1':
				ans += 1
			elif i < n - 1 and s[i + 1] == '1':
				ans += 1
				s[i + 1] = '2'
	l.append(ans)
print(*l, sep='\n')


for _ in range(int(input())):
	n = int(input())
	t = list(input())
	our = input()
	mx = 0
	for i in range(n):
		if our[i] == '1':
			if t[i] == '0':
				t[i] = '2'
				mx += 1
			else:
				shift = 0
				if i + 1 < n:
					if t[i + 1] == '1':
						shift = 1
				if i - 1 >= 0:
					if t[i - 1] == '1':
						shift = -1
				if shift:
					t[i + shift] = '2'
					mx += 1
	print(mx)


def solve(a, l):
	occ = [0] * len(a)
	ans = 0
	n = len(a)
	if n == 1:
		if a[0] == 0:
			return 0
		if l[i] == 1:
			return 0
		else:
			return 1
	for i in range(len(a)):
		if a[i] == 1:
			if l[i] == 0:
				ans += 1
				occ[i] = 1
			elif i != 0 and i != n - 1:
				if l[i - 1] == 1 and occ[i - 1] == 0:
					ans += 1
					occ[i - 1] = 1
				elif l[i + 1] == 1 and occ[i + 1] == 0:
					ans += 1
					occ[i + 1] = 1
			elif i == 0:
				if l[i + 1] == 1:
					ans += 1
					occ[i + 1] = 1
			elif i == n - 1:
				if l[i - 1] == 1 and occ[i - 1] == 0:
					ans += 1
					occ[i - 1] = 1
	return ans
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input()))
	a = list(map(int, input()))
	print(solve(a, l))


t = int(input())
for i in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	a = list(s1)
	b = list(s2)
	c = 0
	for j in range(n):
		if b[j] == '1':
			if a[j] == '0':
				c = c + 1
			elif j > 0 and a[j - 1] == '1':
				c = c + 1
				a[j - 1] = '!'
			elif j < n - 1 and a[j + 1] == '1':
				c = c + 1
				a[j + 1] = '!'
	print(c)


mod = 1000000007
from sys import stdin, stdout
from collections import defaultdict, Counter, deque
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s1 = list(stdin.readline().strip('\n'))
	s2 = list(stdin.readline().strip('\n'))
	count = 0
	for i in range(n):
		if s2[i] == '1' and s1[i] == '0':
			count += 1
		elif s2[i] == '1':
			if i > 0 and s1[i - 1] == '1':
				count += 1
				s1[i - 1] = '-1'
			elif i < n - 1 and s1[i + 1] == '1':
				count += 1
				s1[i + 1] = '-1'
	print(count)


for _ in range(int(input())):
	n = int(input())
	captured = [False] * n
	opp = input()
	me = input()
	result = 0
	for index in range(n):
		if me[index] == '1':
			if index > 0 and opp[index - 1] == '1' and (not captured[index - 1]):
				result += 1
			elif opp[index] == '0':
				result += 1
			elif index < n - 1 and opp[index + 1] == '1':
				result += 1
				captured[index + 1] = True
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(input())
	b = list(input())
	a.append('0')
	b.append('0')
	c = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				c += 1
			elif a[i - 1] == '1':
				a[i - 1] = '0'
				c += 1
			elif a[i + 1] == '1':
				a[i + 1] = '0'
				c += 1
	print(c)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	(A, B) = (list(map(int, list(input()[:-1]))), list(map(int, list(input()[:-1]))))
	ans = 0
	for (i, b) in enumerate(B):
		if not b:
			continue
		if i and A[i - 1] == 1:
			A[i - 1] = 2
			ans += 1
		elif not A[i]:
			A[i] = 2
			ans += 1
		elif i < n - 1 and A[i + 1] == 1:
			A[i + 1] = 2
			ans += 1
	print(ans)


for T in range(int(input())):
	N = int(input())
	opponent = list(input())
	player = list(input())
	count = 0
	if player[0] == '1':
		if opponent[0] == '0':
			opponent[0] = '-1'
			count += 1
		elif opponent[1] == '1':
			opponent[1] = '-1'
			count += 1
	for i in range(1, N - 1):
		if player[i] == '1':
			if opponent[i - 1] == '1':
				opponent[i - 1] = '-1'
				count += 1
			elif opponent[i] == '0':
				opponent[i] = '-1'
				count += 1
			elif opponent[i + 1] == '1':
				opponent[i + 1] = '-1'
				count += 1
	if player[N - 1] == '1':
		if opponent[N - 2] == '1' or opponent[N - 1] == '0':
			count += 1
	print(count)


import io
import os

def solve():
	n = int(input())
	enemy = list(map(int, input()))
	greg = list(map(int, input()))
	taken = [False] * n
	count = 0
	for (i, (e, g)) in enumerate(zip(enemy, greg)):
		if not g:
			continue
		if not e:
			count += 1
			continue
		if i > 0 and enemy[i - 1] and (not taken[i - 1]):
			count += 1
		elif i < n - 1 and enemy[i + 1]:
			count += 1
			taken[i + 1] = True
	print(count)
t = int(input())
for _ in range(t):
	solve()


t = int(input())
lan = []
for _ in range(t):
	n = int(input())
	up = list(input())
	down = input()
	ctr = 0
	for indx in range(n):
		if indx == 0 and down[indx] == '1':
			if up[indx] == '0':
				up[indx] = '2'
				ctr += 1
			elif up[indx + 1] == '1':
				up[indx + 1] = '2'
				ctr += 1
		elif indx == n - 1 and down[indx] == '1':
			if up[indx] == '0':
				up[indx] = '2'
				ctr += 1
			elif up[indx - 1] == '1':
				up[indx - 1] = '2'
				ctr += 1
		elif indx > 0 and indx < n - 1 and (down[indx] == '1'):
			if up[indx - 1] == '1':
				up[indx - 1] = '2'
				ctr += 1
			elif up[indx] == '0':
				up[indx] = '2'
				ctr += 1
			elif up[indx + 1] == '1':
				up[indx + 1] = '2'
				ctr += 1
	lan.append(ctr)
print(*lan, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	b = list(map(int, input()))
	w = list(map(int, input()))
	c = 0
	if w[0]:
		if b[0] == 0:
			b[0] = 2
		elif b[1] == 1:
			b[1] = 2
	for i in range(1, n - 1):
		if w[i] == 0:
			continue
		if b[i] == 0:
			b[i] = 2
		elif b[i - 1] == 1:
			b[i - 1] = 2
		elif b[i + 1] == 1:
			b[i + 1] = 2
	if w[n - 1]:
		if b[n - 1] == 0:
			b[n - 1] = 2
		elif b[n - 2] == 1:
			b[n - 2] = 2
	print(b.count(2))


for i in range(int(input())):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	ans = 0
	occupied = [0] * n
	for i in range(n):
		if s2[i] == '0':
			continue
		if s1[i] == '0':
			occupied[i] = 1
			ans += 1
		elif i > 0 and s1[i - 1] == '1' and (occupied[i - 1] == 0):
			occupied[i - 1] = 1
			ans += 1
		elif i < n - 1 and s1[i + 1] == '1' and (occupied[i + 1] == 0):
			occupied[i + 1] = 1
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	l1 = list(input())
	l1.append(2)
	l2 = list(input())
	c = 0
	for i in range(len(l2)):
		if l2[i] == '1':
			if l1[i] == '0':
				l1[i] = '2'
				l2[i] = '0'
				c = c + 1
	for i in range(len(l2)):
		if l2[i] == '1':
			if l1[i - 1] == '1':
				l1[i - 1] = '2'
				l2[i] = '0'
				c = c + 1
			elif l1[i + 1] == '1':
				l1[i + 1] = '2'
				l2[i] = '0'
				c = c + 1
	print(c)


from math import inf

def pro(a, b):
	n = len(a)
	ans = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				a[i] = -1
				ans += 1
			else:
				if i - 1 >= 0 and a[i - 1] == '1':
					a[i - 1] = -1
					ans += 1
					continue
				if i + 1 < n and a[i + 1] == '1':
					a[i + 1] = -1
					ans += 1
					continue
	print(ans)
t = int(input())
for i in range(t):
	n = int(input())
	a = input()
	arr = input()
	pro(list(a), list(arr))


import collections
import itertools
from collections import defaultdict
import sys
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.buffer.readline())

def MI():
	return map(int, sys.stdin.buffer.readline().split())

def LI():
	return list(map(int, sys.stdin.buffer.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def BI():
	return sys.stdin.buffer.readline().rstrip()

def SI():
	return sys.stdin.buffer.readline().rstrip().decode()

def li():
	return [int(i) for i in input().split()]

def lli(rows):
	return [li() for _ in range(rows)]

def si():
	return input()

def ii():
	return int(input())

def ins():
	return input().split()

def solve():
	n = II()
	pe = []
	ge = []
	ans = 0
	for i in SI():
		pe.append(i)
	for i in SI():
		ge.append(i)
	for i in range(n):
		if pe[i] == '0' and ge[i] == '1':
			ans += 1
			ge[i] = '0'
		elif pe[i] == '1':
			if i > 0 and ge[i - 1] == '1':
				ans += 1
				ge[i - 1] = '0'
			elif i < n - 1 and ge[i + 1] == '1':
				ans += 1
				ge[i + 1] = '0'
	return ans

def main():
	for _ in range(II()):
		sys.stdout.write(str(solve()) + '\n')
main()


t = int(input())
for i in range(t):
	n = int(input())
	s1 = list('0' + input() + '0')
	s2 = input()
	k = 0
	for i in range(n):
		if s2[i] != '1':
			continue
		if s1[i + 1] == '0':
			s1[i + 1] = '2'
			k += 1
		elif s1[i] == '1':
			s1[i] = '2'
			k += 1
		elif s1[i + 2] == '1':
			s1[i + 2] = '2'
			k += 1
	print(k)


for _ in range(int(input())):
	n = int(input())
	c = 0
	l = list(input())
	k = list(input())
	for i in range(n):
		if k[i] == '0':
			continue
		if l[i] == '0':
			c += 1
		elif i and l[i - 1] == '1':
			c += 1
		elif i + 1 < n and l[i + 1] == '1':
			l[i + 1] = '0'
			c += 1
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	enemy = input()
	my = input()
	enemy_arr = []
	my_arr = []
	result = 0
	for i in range(0, n, 1):
		enemy_arr.append(int(enemy[i]))
		my_arr.append(int(my[i]))
	for i in range(0, n, 1):
		if my_arr[i] == 1 and enemy_arr[i] == 0:
			enemy_arr[i] = -1
			result = result + 1
		elif my_arr[i] == 1 and enemy_arr[i] != 0:
			if i < n - 1 and i > 0:
				if enemy_arr[i - 1] == 1:
					enemy_arr[i - 1] = -1
					result = result + 1
				elif enemy_arr[i + 1] == 1:
					enemy_arr[i + 1] = -1
					result = result + 1
			if i == 0:
				if enemy_arr[i + 1] == 1:
					enemy_arr[i + 1] = -1
					result = result + 1
			if i == n - 1:
				if enemy_arr[i - 1] == 1:
					enemy_arr[i - 1] = -1
					result = result + 1
	print(result)
	t = t - 1


def result(first, second, length):
	result = list(first)
	count = 0
	for i in range(length):
		if second[i] == '1':
			if first[i] == '0':
				result[i] = '2'
				count += 1
			elif first[i] == '1' and i - 1 >= 0 and (result[i - 1] == '1') and (first[i - 1] == '1'):
				result[i - 1] = '2'
				count += 1
			elif first[i] == '1' and i + 1 < length and (result[i + 1] == '1') and (first[i + 1] == '1'):
				result[i + 1] = '2'
				count += 1
	print(count)
for i in range(int(input())):
	length = int(input())
	a = input()
	b = input()
	result(a, b, length)


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	ans = 0
	occupied = [0] * n
	for i in range(n):
		if s2[i] == '0':
			continue
		if s1[i] == '0':
			occupied[i] = 1
			ans += 1
		elif i > 0 and s1[i - 1] == '1' and (occupied[i - 1] == 0):
			occupied[i - 1] = 1
			ans += 1
		elif i < n - 1 and s1[i + 1] == '1' and (occupied[i + 1] == 0):
			occupied[i + 1] = 1
			ans += 1
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	ans = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				ans += 1
			elif i >= 1 and a[i - 1] == '1':
				ans += 1
				a[i - 1] = '0'
			elif i < n - 1 and a[i + 1] == '1':
				ans += 1
				a[i + 1] = '0'
	print(ans)


import math, os, io, sys
from collections import Counter
import heapq
from collections import deque

def getList(method=int):
	return list(map(method, input().split()))

def getInt():
	return int(input())

def solve():
	n = getInt()
	e = input()
	g = input()
	occ = set()
	ans = 0
	for i in range(n):
		if g[i] == '1':
			if e[i] == '0':
				ans += 1
			elif i - 1 > -1 and e[i - 1] == '1' and (i - 1 not in occ):
				ans += 1
			elif i + 1 < n and e[i + 1] == '1':
				ans += 1
				occ.add(i + 1)
	return ans
for _ in range(getInt()):
	print(solve())


t = int(input())
for i in range(t):
	sz = int(input())
	enemy = input()
	enemy = list(enemy)
	gregor = input()
	gregor = list(gregor)
	ret = 0
	for (idx, item) in enumerate(gregor):
		if item == '1' and idx - 1 >= 0 and (enemy[idx - 1] == '1'):
			enemy[idx - 1] = '2'
			ret += 1
		elif item == '1' and enemy[idx] == '0':
			enemy[idx] = '2'
			ret += 1
		elif item == '1' and enemy[idx] == '1' and (idx + 1 < sz) and (enemy[idx + 1] == '1'):
			enemy[idx + 1] = '2'
			ret += 1
	print(ret)


t = int(input())
testcases = [(int(input()), list(map(int, input())), list(map(int, input()))) for _ in range(t)]
for (n, enemy, gregor) in testcases:
	if gregor.count(1) == 0:
		print(0)
		continue
	count = 0
	for i in range(n):
		if gregor[i] == 1:
			if enemy[i] == 0:
				count += 1
			elif i > 0 and enemy[i - 1] == 1:
				count += 1
			elif i < n - 1 and enemy[i + 1] == 1:
				count += 1
				enemy[i + 1] = 0
	print(count)


for _ in range(int(input())):
	n = int(input())
	(lst1, lst2) = (list(), list())
	res = 0
	lst1 += input()
	lst2 += input()
	for i in range(n):
		if lst2[i] == '1':
			if lst1[i] == '0':
				res += 1
				lst1[i] = 'X'
			elif i == 0 and lst1[i + 1] == '1':
				res += 1
				lst1[i + 1] = 'X'
			elif i == n - 1 and lst1[i - 1] == '1':
				res += 1
				lst1[i - 1] = 'X'
			elif (i != 0 and i != n - 1) and lst1[i - 1] == '1':
				res += 1
				lst1[i - 1] = 'X'
			elif (i != 0 and i != n - 1) and lst1[i + 1] == '1':
				res += 1
				lst1[i + 1] = 'X'
	print(res)


for _ in range(int(input())):
	n = int(input())
	first = input()
	second = input()
	li = [False] * n
	for i in range(n):
		if second[i] == '1':
			if first[i] == '0':
				li[i] = True
			elif i - 1 >= 0 and first[i - 1] == '1' and (li[i - 1] == False):
				li[i - 1] = True
			elif i + 1 < n and first[i + 1] == '1' and (li[i + 1] == False):
				li[i + 1] = True
	print(li.count(True))


import sys, os, io
input = sys.stdin.readline
PI = 3.141592653589793
INF = float('inf')
MOD = 1000000007

def bin32(num):
	return '{0:032b}'.format(num)

def add(x, y):
	return (x + y) % MOD

def sub(x, y):
	return (x - y + MOD) % MOD

def mul(x, y):
	return x * y % MOD

def gcd(x, y):
	if y == 0:
		return x
	return gcd(y, x % y)

def lcm(x, y):
	return x * y // gcd(x, y)

def power(x, y):
	res = 1
	x %= MOD
	while y != 0:
		if y & 1:
			res = mul(res, x)
		y >>= 1
		x = mul(x, x)
	return res

def mod_inv(n):
	return power(n, MOD - 2)

def prob(p, q):
	return mul(p, power(q, MOD - 2))

def ii():
	return int(input())

def li():
	return [int(i) for i in input().split()]

def ls():
	return [i for i in input().split()]
for t in range(ii()):
	t += 1
	n = ii()
	a = input()
	b = input()
	a = list(a)
	b = list(b)
	ans = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				ans += 1
			else:
				if i != 0:
					if a[i - 1] == '1':
						ans += 1
						continue
				if i != n - 1:
					if a[i + 1] == '1':
						ans += 1
						a[i + 1] = '-1'
	print(ans)


T = int(input())
for _ in range(T):
	n = int(input())
	str1 = input()
	str2 = input()
	arr1 = list(str1)
	arr2 = list(str2)
	ans = 0
	if arr2[0] == '1':
		if arr1[0] == '0':
			ans += 1
		elif arr1[1] == '1':
			arr1[1] = '0'
			ans += 1
	for i in range(1, n - 1):
		if arr2[i] == '1':
			if arr1[i - 1] == '1':
				ans += 1
				arr1[i - 1] = '0'
			elif arr1[i] == '0':
				ans += 1
			elif arr1[i + 1] == '1':
				ans += 1
				arr1[i + 1] = '0'
	if arr2[n - 1] == '1':
		if arr1[n - 1] == '0':
			ans += 1
		elif arr1[n - 2] == '1':
			ans += 1
			arr1[n - 2] = '0'
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s = list(map(int, list(input())))
	m = list(map(int, list(input())))
	ans = 0
	if m[0] == 1:
		if s[0] == 0:
			ans += 1
		elif s[1] == 1:
			ans += 1
			s[1] = 2
	for x in range(1, n):
		if m[x] == 1:
			if s[x] == 0:
				ans += 1
			elif s[x - 1] == 1:
				ans += 1
			elif x + 1 != n and s[x + 1] == 1:
				ans += 1
				s[x + 1] = 2
	print(ans)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	enemy = input()
	gregor = input()
	count = 0
	prev_available = False
	cur_available = True
	for i in range(n):
		if gregor[i] == '1' and enemy[i] == '0':
			count += 1
			(prev_available, cur_available) = (False, True)
		elif gregor[i] == '1' and prev_available:
			count += 1
			(prev_available, cur_available) = (cur_available, True)
		elif gregor[i] == '1' and i < n - 1 and (enemy[i + 1] == '1'):
			count += 1
			(prev_available, cur_available) = (cur_available, False)
		elif gregor[i] == '1':
			(prev_available, cur_available) = (cur_available, True)
		elif enemy[i] == '0':
			(prev_available, cur_available) = (False, True)
		elif enemy[i] == '1':
			(prev_available, cur_available) = (cur_available, True)
	print(count)


n = int(input())
for i in range(n):
	win = 0
	l = int(input())
	ent = list(input())
	greg = list(input())
	for x in range(l):
		if greg[x] == '1':
			if ent[x] == '0':
				win += 1
				ent[x] = '2'
			elif x - 1 >= 0 and ent[x - 1] == '1':
				win += 1
				ent[x - 1] = '2'
			elif x + 1 < l and ent[x + 1] == '1':
				win += 1
				ent[x + 1] = '2'
	print(win)


for i in range(int(input())):
	a = int(input())
	b = input()
	c = input()
	m = []
	n = []
	for i in range(a):
		m.append(b[i])
		n.append(c[i])
	count = 0
	for i in range(a):
		if n[i] == '1' and m[i] == '0':
			count += 1
			m[i] = '2'
			continue
		if n[i] == '1' and i != 0 and (m[i - 1] == '1'):
			count += 1
			m[i - 1] = '2'
			continue
		if n[i] == '1' and i != a - 1 and (m[i + 1] == '1'):
			count += 1
			m[i + 1] = '2'
			continue
	print(count)


import sys

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_list_string():
	return list(map(str, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()

def get_int():
	return int(sys.stdin.readline().strip())

def get_print_int(x):
	sys.stdout.write(str(x) + '\n')

def get_print(x):
	sys.stdout.write(x + '\n')

def get_print_int_same(x):
	sys.stdout.write(str(x) + ' ')

def get_print_same(x):
	sys.stdout.write(x + ' ')
from sys import maxsize

def solve():
	for _ in range(get_int()):
		n = get_int()
		s1 = get_string()
		s2 = get_string()
		d1 = list(s1)
		d2 = list(s2)
		ans = 0
		for i in range(n):
			if d2[i] == '1':
				if d1[i] == '0':
					ans += 1
				elif i - 1 >= 0 and d1[i - 1] == '1':
					ans += 1
					d1[i - 1] = '0'
				elif i + 1 < n and d1[i + 1] == '1':
					ans += 1
					d1[i + 1] = '0'
		get_print_int(ans)
solve()


def answer(enemy, gregory):
	result = 0
	for i in range(len(gregory)):
		if enemy[i] == '0':
			if gregory[i] == '1':
				gregory[i] = '-1'
				result += 1
		elif i - 1 >= 0 and gregory[i - 1] == '1':
			result += 1
		elif i + 1 <= len(gregory) - 1 and gregory[i + 1] == '1':
			result += 1
			gregory[i + 1] = '-1'
	return result
test = int(input())
for i in range(test):
	n = int(input())
	enemy = list(input())
	gregory = list(input())
	print(answer(enemy, gregory))


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	arr_1 = list(sys.stdin.readline().strip())
	arr_2 = list(sys.stdin.readline().strip())
	count = 0
	for i in range(len(arr_1) - 1):
		if arr_1[i] == '0' and arr_2[i] == '1':
			arr_1[i] = '2'
			arr_2[i] = '0'
			count += 1
		if arr_1[i + 1] == '0' and arr_2[i + 1] == '1':
			arr_1[i + 1] = '2'
			arr_2[i + 1] = '0'
			count += 1
		if arr_1[i] == '1' and arr_2[i + 1] == '1':
			arr_1[i] = '2'
			arr_2[i + 1] = '0'
			count += 1
		if arr_1[i + 1] == '1' and arr_2[i] == '1':
			arr_1[i + 1] = '0'
			arr_2[i] = '0'
			count += 1
	print(count)


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(stdin.readline().strip())
	b = list(stdin.readline().strip())
	res = 0
	for i in range(n):
		if b[i] == '1':
			if i > 0 and a[i - 1] == '1':
				res += 1
			elif a[i] == '0':
				res += 1
			elif i < n - 1 and a[i + 1] == '1':
				res += 1
				a[i + 1] = '2'
	print(res)


def sol(A, B):
	sett = set()
	count = 0
	for i in range(len(B)):
		if B[i] == '1':
			if A[i] == '0':
				count += 1
			elif i - 1 >= 0 and A[i - 1] == '1' and (i - 1 not in sett):
				count += 1
				sett.add(i - 1)
			elif i + 1 <= len(B) - 1 and A[i + 1] == '1' and (i + 1 not in sett):
				count += 1
				sett.add(i + 1)
	return count
x = int(input())
for _ in range(x):
	y = input()
	A = input()
	B = input()
	print(sol(A, B))


from math import *
from math import factorial as fact, comb as ncr
from bisect import bisect_left as bl
from bisect import bisect_right as br
from collections import Counter as ctr
from collections import deque as dq
from array import array
from re import search
li = lambda : list(map(int, input().split()))
arr = lambda a: array('i', a)
bi = lambda n: bin(n).replace('0b', '')
yn = lambda f: print('NYOE S'[f::2])
sbstr = lambda a, s: search('.*'.join(a), s)

def gcdsum(n):
	s = sum((int(x) for x in str(n)))
	return gcd(n, s)

def solve():
	for _ in range(int(input())):
		n = int(input())
		a = list(input())
		b = input()
		t = False
		ans = 0
		for i in range(n):
			if b[i] == '1':
				if a[i] == '0':
					ans += 1
				elif i > 0 and a[i - 1] == '1':
					ans += 1
					a[i - 1] = '#'
				elif i < n - 1 and a[i + 1] == '1':
					ans += 1
					a[i + 1] = '#'
		print(ans)
solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
tt = int(input())
for qq in range(tt):
	n = int(input())
	s = [i for i in input()]
	t = [i for i in input()]
	cnt = 0
	if t[0] == '1' and s[0] == '0':
		cnt += 1
		s[0] = '-1'
	elif t[0] == '1' and s[1] == '1':
		cnt += 1
		s[1] = '-1'
	for i in range(1, n):
		if t[i] == '1':
			if s[i - 1] == '1':
				cnt += 1
				s[i - 1] = '-1'
			elif s[i] == '0':
				cnt += 1
				s[i] = '-1'
			elif i + 1 < n and s[i + 1] == '1':
				cnt += 1
				s[i + 1] = '-1'
	print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	ls1 = list(input())
	ls2 = list(input())
	s = 0
	for i in range(n):
		if ls2[i] == '1':
			if i > 0:
				if ls1[i - 1] == '1':
					ls1[i - 1] = '2'
					s += 1
					continue
			if ls1[i] == '0':
				ls1[i] = '2'
				s += 1
				continue
			if i < n - 1:
				if ls1[i + 1] == '1':
					ls1[i + 1] = '2'
					s += 1
	print(s)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
for t in range(int(input())):
	n = int(input())
	enemy = list(input())
	gregor = list(input())
	indices = []
	indices = set(indices)
	usedindices = []
	ans = 0
	for i in range(n):
		if enemy[i] == '1':
			indices.add(i)
	if indices == []:
		print(gregor.count('1'))
		continue
	for i in range(n):
		if gregor[i] == '1':
			if i in indices:
				if i - 1 in indices:
					ans += 1
					indices.remove(i - 1)
				elif i + 1 in indices:
					ans += 1
					indices.remove(i + 1)
			else:
				ans += 1
	print(ans)


import math
mod = 1000000007
from sys import stdin, stdout
for abcd in range(int(input())):
	n = int(stdin.readline())
	t = list(stdin.readline().strip('\n'))
	s = list(stdin.readline().strip('\n'))
	if n == 1:
		if t[i] == '0':
			print(0)
		elif t[i] == '1':
			if s[i] == '1':
				print(0)
			else:
				print(1)
		else:
			print(0)
		continue
	c = 0
	for i in range(n):
		if s[i] == '1':
			if i == 0:
				if t[i] == '0':
					c += 1
				elif t[i + 1] == '1':
					c += 1
					t[i + 1] = 0
			elif i == n - 1:
				if t[i] == '0':
					c += 1
				elif t[i - 1] == '1':
					c += 1
					t[i - 1] = 0
			elif t[i] == '0':
				c += 1
			elif t[i - 1] == '1':
				c += 1
				t[i - 1] = 0
			elif t[i + 1] == '1':
				c += 1
				t[i + 1] = 0
	print(c)


t = int(input())
while t:
	n = int(input())
	enemy = list(input())
	enemy = ['0'] + enemy + ['0']
	greg = input()
	cnt = 0
	for i in range(len(greg)):
		if greg[i] == '1':
			if enemy[i + 1] == '0':
				cnt += 1
			elif enemy[i] == '1':
				cnt += 1
				enemy[i] = '0'
			elif enemy[i + 2] == '1':
				cnt += 1
				enemy[i + 2] = '0'
	print(cnt)
	t -= 1


t = int(input())
while t:
	t -= 1
	n = int(input())
	blocked = [0] * n
	count = 0
	l0 = str(input())
	l1 = str(input())
	for i in range(n):
		if l1[i] == '1':
			if l0[i] == '0':
				count += 1
				continue
			if i > 0:
				if l0[i - 1] == '1':
					if blocked[i - 1] == 0:
						count += 1
						blocked[i - 1] = 1
						continue
			if i < n - 1:
				if l0[i + 1] == '1':
					if blocked[i + 1] == 0:
						count += 1
						blocked[i + 1] = 1
						continue
	print(count)


import sys
import math
import bisect
t = int(input())
for a0 in range(t):
	n = int(input())
	s1 = input()
	s2 = input()
	c = 0
	f = [0] * n
	if s2[0] == '1' and s1[0] == '0':
		c += 1
		f[0] = 1
	elif s2[0] == '1' and s1[1] == '1':
		c += 1
		f[1] = 1
	for i in range(1, n - 1):
		if s2[i] == '1':
			if s1[i - 1] == '1' and f[i - 1] == 0:
				c += 1
				f[i - 1] = 1
			elif s1[i] == '0':
				c += 1
				f[i] = 1
			elif s1[i + 1] == '1' and f[i + 1] == 0:
				c += 1
				f[i + 1] = 1
	if s2[n - 1] == '1' and s1[n - 2] == '1' and (f[n - 2] == 0):
		c += 1
	elif s2[n - 1] == '1' and s1[n - 1] == '0':
		c += 1
	print(c)


T = int(input())
res = [0] * T
for i in range(T):
	N = int(input())
	O = list(map(lambda x: int(x), list(input())))
	P = list(map(lambda x: int(x), list(input())))
	j = 0
	while j < N:
		if P[j] == 1:
			if O[j] == 0:
				res[i] += 1
			elif j > 0 and O[j - 1] == 1:
				res[i] += 1
			elif j < N - 1 and O[j + 1] == 1:
				O[j + 1] = 0
				res[i] += 1
		j += 1
[print(r) for r in res]


T = int(input())
while T:
	n = int(input())
	ans = 0
	a1 = list(input())
	a2 = list(input())
	for (i, ele) in enumerate(a2):
		if ele == '1':
			if a1[i] == '0':
				a1[i] = '2'
				ans += 1
			elif i - 1 >= 0 and a1[i - 1] == '1':
				a1[i - 1] = 2
				ans += 1
			elif i + 1 < n and a1[i + 1] == '1':
				a1[i + 1] = 2
				ans += 1
	print(ans)
	T -= 1


tests = int(input())
for _ in range(tests):
	n = int(input())
	res = 0
	s1 = [c for c in input()]
	s2 = [c for c in input()]
	if s2[n - 1] == '1' and s1[n - 1] == '0':
		res += 1
		s1[n - 1] = '*'
	elif s2[n - 1] == '1' and s1[n - 2] == '1':
		res += 1
		s1[n - 2] = '*'
	if s2[0] == '1' and s1[0] == '0':
		res += 1
		s1[0] = '*'
	elif s2[0] == '1' and s1[1] == '1':
		res += 1
		s1[1] = '*'
	for i in range(1, n - 1):
		if s2[i] == '1' and s1[i] == '0':
			res += 1
			s1[i] == '*'
		elif s2[i] == '1' and s1[i - 1] == '1':
			res += 1
			s1[i - 1] = '*'
		elif s2[i] == '1' and s1[i + 1] == '1':
			res += 1
			s1[i + 1] = '*'
	print(res)


import logging
l = logging.Logger('')
h = logging.StreamHandler()
f = logging.Formatter(fmt='[{filename}:{lineno}] {msg}', style='{')
h.setFormatter(f)
l.addHandler(h)
bug = l.info
from math import sqrt

def main():
	t = int(input())
	for T in range(t):
		size = int(input())
		enemy = list(input())
		allie = list(input())
		total = 0
		for i in range(size):
			if allie[i] == '1':
				if enemy[i] == '0':
					total += 1
					continue
				if i > 0 and enemy[i - 1] == '1':
					total += 1
					enemy[i - 1] = '#'
					continue
				if i < size - 1 and enemy[i + 1] == '1':
					total += 1
					enemy[i + 1] = '#'
					continue
		print(total)
main()


import sys, os, io
from sys import stdin, stdout
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import math
alphabets = list('abcdefghijklmnopqrstuvwxyz')

def isPrime(x):
	for i in range(2, x):
		if i * i > x:
			break
		if x % i == 0:
			return False
	return True

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(int(i))
			n = n / i
	if n > 2:
		l.append(n)
	return list(set(l))

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def si():
	return input()

def prefix_sum(arr):
	r = [0] * (len(arr) + 1)
	for (i, el) in enumerate(arr):
		r[i + 1] = r[i] + el
	return r

def divideCeil(n, x):
	if n % x == 0:
		return n // x
	return n // x + 1

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')

def power_set(L):
	cardinality = len(L)
	n = 2 ** cardinality
	powerset = []
	for i in range(n):
		a = bin(i)[2:]
		subset = []
		for j in range(len(a)):
			if a[-j - 1] == '1':
				subset.append(L[j])
		powerset.append(subset)
	powerset_orderred = []
	for k in range(cardinality + 1):
		for w in powerset:
			if len(w) == k:
				powerset_orderred.append(w)
	return powerset_orderred

def fastPlrintNextLines(a):
	print('\n'.join(map(str, a)))

def sortByFirstAndSecond(A):
	A = sorted(A, key=lambda x: x[0])
	A = sorted(A, key=lambda x: x[1])
	return list(A)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	n = int(input())
	epawn = input()
	gpawn = input()
	epawn = [int(i) for i in epawn]
	gpawn = [int(i) for i in gpawn]
	count = 0
	for i in range(n):
		if epawn[i] == 0 and gpawn[i] == 1:
			count += 1
			epawn[i] = -1
			gpawn[i] = -1
		if i >= 1 and epawn[i - 1] == 1 and (gpawn[i] == 1):
			epawn[i - 1] = -1
			gpawn[i] = -1
			count += 1
		elif i < n - 1 and epawn[i + 1] == 1 and (gpawn[i] == 1):
			epawn[i + 1] = -1
			gpawn[i] = -1
			count += 1
	print(count)


import sys
import math
import heapq
from collections import defaultdict as dd
from collections import OrderedDict as od
from collections import deque
from itertools import permutations as pp
from itertools import combinations as cc
from sys import stdin
from functools import cmp_to_key
from functools import lru_cache
from bisect import bisect_left as bs_l
from bisect import bisect_right as bs_r
input = sys.stdin.readline
mod = 10 ** 9 + 7
sys.setrecursionlimit(10 ** 5)
T = int(input())
for _ in range(T):
	n = int(input())
	s1 = input().strip()
	s2 = input().strip()
	l1 = list(s1)
	l2 = list(s2)
	(l3, l4) = (l1.copy(), l2.copy())
	(ans1, ans2) = (0, 0)
	for i in range(n):
		if l2[i] == '1':
			if i - 1 >= 0 and l1[i - 1] == '1':
				l1[i - 1] = '2'
				ans1 += 1
			elif l1[i] == '0':
				l1[i] = '2'
				ans1 += 1
			elif i + 1 < n and l1[i + 1] == '1':
				l1[i + 1] = '2'
				ans1 += 1
	for i in range(n - 1):
		if l4[i] == '1':
			if i + 1 < n and l3[i + 1] == '1':
				l3[i + 1] = '2'
				ans2 += 1
			elif l3[i] == '0':
				l3[i] = '2'
				ans2 += 1
			elif i - 1 >= 0 and l3[i - 1] == '1':
				l3[i - 1] = '2'
				ans2 += 1
	print(max(ans1, ans2))


from collections import deque
import heapq
from math import sqrt
import operator
from operator import itemgetter
import sys
import copy
inf_var = 0
if inf_var == 1:
	inf = open('input.txt', 'r')
else:
	inf = sys.stdin
input = inf.readline

def read_one_int():
	return int(input().rstrip('\n'))

def read_one_float():
	return float(input().rstrip('\n'))

def read_list_of_ints():
	res = [int(val) for val in input().rstrip('\n').split(' ')]
	return res

def read_str():
	return input().rstrip()

def main():
	tests = read_one_int()
	for _ in range(tests):
		n = read_one_int()
		enemy = list(read_str())
		me = list(read_str())
		cnt = 0
		for i in range(n):
			if me[i] == '0':
				continue
			if enemy[i] == '0':
				cnt += 1
				enemy[i] = '2'
				continue
			prev_i = i - 1
			next_i = i + 1
			if prev_i >= 0:
				if enemy[prev_i] == '1':
					cnt += 1
					enemy[prev_i] = '2'
					continue
			if next_i < n:
				if enemy[next_i] == '1':
					cnt += 1
					enemy[next_i] = '2'
					continue
		print(cnt)
main()


def solves():
	n = int(input())
	enemy = list(input())
	me = list(input())
	ans = 0
	for i in range(0, n):
		if me[i] == '1':
			if i == 0:
				if enemy[0] == '0':
					ans += 1
				elif enemy[1] == '1':
					ans += 1
					enemy[1] = '0'
			elif i == n - 1:
				if enemy[i] == '0':
					ans += 1
				elif enemy[i - 1] == '1':
					ans += 1
					enemy[i - 1] = '0'
			elif enemy[i] == '0':
				ans += 1
			elif enemy[i - 1] == '1':
				ans += 1
				enemy[i - 1] = '0'
			elif enemy[i + 1] == '1':
				ans += 1
				enemy[i + 1] = '0'
	print(ans)
t = int(input())
for _ in range(t):
	solves()


for _ in range(int(input())):
	n = int(input())
	en = input()
	me = input()
	en = list(en)
	ans = 0
	for i in range(n):
		if me[i] == '1':
			if i - 1 >= 0 and en[i - 1] == '1':
				ans += 1
				en[i - 1] = '-1'
			elif en[i] == '0':
				ans += 1
				en[i] = '-1'
			elif i + 1 < n and en[i + 1] == '1':
				ans += 1
				en[i + 1] = '-1'
	print(ans)


import sys

def fun(en, ger, n):
	taken = [False for i in range(n)]
	count = 0
	for i in range(n):
		if ger[i] == '1':
			if i == 0:
				if en[0] == '1' and en[1] == '1':
					taken[1] = True
					count += 1
				elif en[0] == '0':
					taken[0] = True
					count += 1
			elif i == n - 1:
				if en[i] == '1' and en[i - 1] == '1':
					if not taken[i - 1]:
						taken[i - 1] = True
						count += 1
				elif en[i] == '0':
					taken[i] = True
					count += 1
			else:
				if en[i - 1] == '1' and (not taken[i - 1]):
					taken[i - 1] = True
					count += 1
					continue
				if en[i] == '0':
					taken[i] = True
					count += 1
					continue
				if en[i + 1] == '1':
					taken[i + 1] = True
					count += 1
	return count
t = int(sys.stdin.readline())
for i in range(t):
	n = int(sys.stdin.readline())
	en = sys.stdin.readline()
	ger = sys.stdin.readline()
	print(fun(en, ger, n))


from sys import stdin
input = stdin.readline

def f(en, us):
	cnt = 0
	for i in range(len(en)):
		if en[i] == '0' and us[i] == '1':
			en[i] = 'f'
			cnt += 1
		elif i > 0 and en[i - 1] == '1' and (us[i] == '1'):
			en[i - 1] = 'f'
			cnt += 1
		elif i <= len(us) - 2 and en[i + 1] == '1' and (us[i] == '1'):
			en[i + 1] = 'f'
			cnt += 1
	return cnt
for i in range(int(input())):
	s = input()
	en = list(input())
	us = list(input())
	print(f(en, us))


t = int(input())
for i in range(t):
	n = int(input())
	p = input()
	q = input()
	a = [char for char in p]
	b = [char for char in q]
	for i in range(n):
		if a[i] == '0' and b[i] == '1':
			a[i] = '2'
			b[i] = '0'
	for i in range(n):
		if i > 0 and i < n - 1:
			if a[i - 1] == '1' and b[i] == '1':
				a[i - 1] = '2'
			elif a[i + 1] == '1' and b[i] == '1':
				a[i + 1] = '2'
		elif i == 0:
			if a[i + 1] == '1' and b[i] == '1':
				a[i + 1] = '2'
		elif a[i - 1] == '1' and b[i] == '1':
			a[i - 1] = '2'
	c = 0
	for i in range(n):
		if a[i] == '2':
			c += 1
	print(c)


t = int(input())
while t:
	t -= 1
	n = int(input())
	b = input()
	a = input()
	i = c = 0
	s = set()
	while i < n:
		if a[i] == '1' and b[i] == '0':
			c += 1
			i += 1
		elif a[i] == '1' and b[i] == '1':
			if i > 0 and i - 1 not in s and (b[i - 1] == '1'):
				c += 1
				i += 1
			elif i < n - 1 and b[i + 1] == '1':
				c += 1
				s.add(i + 1)
				i += 1
			else:
				i += 1
		else:
			i += 1
	print(c)


tests = int(input())
for _ in range(tests):
	n = int(input())
	busy = [None if c == '0' else False for c in input()]
	pawns = input()
	reached_count = 0
	for i in range(n):
		if pawns[i] == '1':
			if i > 0 and busy[i - 1] is False:
				busy[i - 1] = True
				reached_count += 1
			elif busy[i] is None:
				reached_count += 1
			elif i < n - 1 and busy[i + 1] is False:
				busy[i + 1] = True
				reached_count += 1
	print(reached_count)


for _ in range(int(input())):
	n = int(input())
	black = list(input())
	white = list(input())
	ans = 0
	checkLast = False
	for i in range(n):
		if white[i] == '1':
			if i != 0 and black[i - 1] == '1':
				ans += 1
				black[i - 1] = '-1'
			elif black[i] == '0':
				ans += 1
			elif i != n - 1 and black[i + 1] == '1':
				ans += 1
				black[i + 1] = '-1'
	print(ans)


from typing import Counter
import sys
from collections import defaultdict as dd
from math import *

def vinp():
	return map(int, input().split())

def linp():
	return list(input())

def sinp():
	return input()

def inp():
	return int(input())

def mod(f):
	return f % 1000000007

def pr(*x):
	print(*x)

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def finp():
	f = open('input.txt', 'r')
	f = f.read().split('\n')
	return f

def fout():
	return open('output.txt', 'w')

def fpr(f, x):
	f.write(x + '\n')

def csort(c):
	sorted(c.items(), key=lambda pair: pair[1], reverse=True)

def indc(l, n):
	c = {}
	for i in range(n):
		c[l[i]] = c.get(l[i], []) + [i + 1]
	return c
cou = inp()
for i in range(cou):
	n = inp()
	l = linp()
	l2 = linp()
	c = 0
	for i in range(n):
		p = False
		if l2[i] == '1':
			if l[i] == '1':
				if i != 0:
					if l[i - 1] == '1':
						l[i - 1] = '0'
						p = True
				if i != n - 1 and (not p):
					if l[i + 1] == '1':
						l[i + 1] = '0'
						p = True
				if p:
					c += 1
			else:
				c += 1
	pr(c)


import math
from collections import defaultdict
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ans = 0
	var = 0
	cnt = [0] * (len(a) + 1)
	flag = [0] * (len(b) + 1)
	for i in range(n):
		if a[i] == '0':
			cnt[i] = 0
		else:
			cnt[i] = 1
	res = b
	for i in range(n):
		if b[i] == '1':
			if flag[i - 1] == 0 and i - 1 >= 0 and (cnt[i - 1] == 1):
				flag[i - 1] = 1
				ans += 1
			elif cnt[i] == 0:
				flag[i] = 1
				ans += 1
			elif cnt[i + 1] == 1 and flag[i + 1] == 0 and (i + 1 < n):
				flag[i + 1] = 1
				ans += 1
	for i in range(n):
		flag[i] = 0
	var = max(var, ans)
	ans = 0
	for i in range(n - 1, -1, -1):
		if b[i] == '1':
			if flag[i - 1] == 0 and cnt[i - 1] == 1 and (i - 1 >= 0):
				flag[i - 1] = 1
				ans += 1
			elif cnt[i] == 0:
				flag[i] = 1
				ans += 1
			elif flag[i + 1] == 0 and cnt[i + 1] == 1 and (i + 1 < n):
				flag[i + 1] = 1
				ans += 1
	var = max(ans, var)
	print(var)


for _ in range(int(input())):
	n = int(input())
	s = input()
	w = input()
	count = 0
	signal = -1
	for i in range(n):
		if w[i] == '1':
			if s[i] == '0':
				count += 1
			elif i != 0 and s[i - 1] == '1' and (i - 1 != signal):
				count += 1
			elif i != n - 1 and s[i + 1] == '1':
				count += 1
				signal = i + 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	c = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				c += 1
			elif i == 0:
				if a[i + 1] == '1':
					c += 1
					a[i + 1] = 'x'
			elif a[i - 1] == '1':
				c += 1
				a[i - 1] = 'x'
			elif i + 1 < n and a[i + 1] == '1':
				c += 1
				a[i + 1] = 'x'
	print(c)


t = int(input())
for i in range(0, t):
	n = int(input())
	enemy = list(input())
	mine = input()
	count = 0
	for x in range(0, n):
		if mine[x] == '1':
			if enemy[x] == '0':
				count += 1
			elif x - 1 >= 0 and enemy[x - 1] == '1':
				enemy[x - 1] = '*'
				count += 1
			elif x + 1 < n and enemy[x + 1] == '1':
				enemy[x + 1] = '*'
				count += 1
	print(count)


n = int(input())
for i in range(n):
	m = int(input())
	x2 = list(input())
	x1 = list(input())
	y = 0
	for j in range(m):
		if x1[j] == '1':
			if j == 0:
				if x2[j] == '0':
					y += 1
				elif x2[j + 1] == '1':
					y += 1
					x2[j + 1] = ''
			elif j == m - 1:
				if x2[j] == '0':
					y += 1
				elif x2[j - 1] == '1':
					y += 1
					x2[j - 1] = ''
			elif x2[j] == '0':
				y += 1
			elif x2[j - 1] == '1':
				y += 1
				x2[j - 1] = ''
			elif x2[j + 1] == '1':
				y += 1
				x2[j + 1] = ''
	print(y)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = ri()
	for _ in range(tc):
		n = ri()
		a = list(rs())
		b = list(rs())
		for i in range(n):
			if b[i] == '1':
				if i - 1 >= 0 and a[i - 1] == '1':
					a[i - 1] = 'd'
				elif a[i] == '0':
					a[i] = 'd'
				elif i + 1 < n and a[i + 1] == '1':
					a[i + 1] = 'd'
		wi(Counter(a)['d'])
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


for _ in range(int(input())):
	n = int(input())
	Y = list(input())
	X = list(input())
	count = 0
	for j in range(n):
		if j == 0:
			a = None
			b = Y[0]
			c = Y[1]
		elif j == n - 1:
			a = Y[n - 2]
			b = Y[n - 1]
			c = None
		else:
			a = Y[j - 1]
			b = Y[j]
			c = Y[j + 1]
		if X[j] == '1':
			if b == '0':
				count += 1
			elif b == '1':
				if a == '1':
					count += 1
					Y[j - 1] = '0'
				elif c == '1':
					count += 1
					Y[j + 1] = '0'
	print(count)


T = int(input())
for t in range(T):
	n = int(input())
	board = [list(map(int, list(input()))) for i in range(2)]
	moves = 0
	for i in range(n):
		if board[1][i]:
			if board[0][i] == 0:
				moves += 1
				board[0][i] = 2
			elif i > 0 and board[0][i - 1] == 1:
				moves += 1
				board[0][i - 1] = 2
			elif i < n - 1 and board[0][i + 1] == 1:
				moves += 1
				board[0][i + 1] = 2
	print(moves)


import sys
input = sys.stdin
output = sys.stdout
t = int(input.readline().strip())
for y in range(t):
	n = int(input.readline().strip())
	enemy = list('0' + input.readline().strip() + '0')
	friendly = list('0' + input.readline().strip() + '0')
	count = 0
	for i in range(1, n + 1):
		if friendly[i] == '1':
			if enemy[i - 1] == '1':
				count += 1
				enemy[i - 1] = '2'
			elif enemy[i] == '0':
				count += 1
				enemy[i] = '2'
			elif enemy[i + 1] == '1':
				count += 1
				enemy[i + 1] = '2'
	print(count)


import os.path
from math import gcd, floor, ceil
from collections import *
import sys
mod = 1000000007
INF = float('inf')

def st():
	return list(sys.stdin.readline().strip())

def li():
	return list(map(int, sys.stdin.readline().split()))

def mp():
	return map(int, sys.stdin.readline().split())

def inp():
	return int(sys.stdin.readline())

def pr(n):
	return sys.stdout.write(str(n) + '\n')

def prl(n):
	return sys.stdout.write(str(n) + ' ')
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	n = inp()
	a = st()
	b = st()
	a = list(map(int, a))
	b = list(map(int, b))
	ans = 0
	for i in range(n):
		if a[i]:
			if i - 1 >= 0:
				if b[i - 1]:
					ans += 1
					b[i - 1] ^= 1
					continue
			if i + 1 < n:
				if b[i + 1]:
					ans += 1
					b[i + 1] ^= 1
		elif b[i]:
			ans += 1
			b[i] = 0
	pr(ans)
for _ in range(inp()):
	solve()


for _ in range(int(input())):
	n = int(input())
	e = input()
	m = input()
	e = list(e)
	m = list(m)
	ans = 0
	for i in range(n):
		if e[i] == '0' and m[i] == '1':
			ans += 1
			m[i] = '0'
	for i in range(n):
		if e[i] == '1':
			if i > 0 and m[i - 1] == '1':
				m[i - 1] = '0'
				ans += 1
			elif i < n - 1 and m[i + 1] == '1':
				m[i + 1] = '0'
				ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	e = list(map(int, input()))
	o = list(map(int, input()))
	ans = 0
	used = [0] * n
	for i in range(n):
		if o[i] == 0:
			continue
		if e[i] == 0:
			ans += 1
		elif i > 0 and e[i - 1] == 1 and (used[i - 1] == 0):
			ans += 1
			used[i - 1] = 1
		elif i < n - 1 and e[i + 1] == 1 and (used[i + 1] == 0):
			ans += 1
			used[i + 1] = 1
	print(ans)


def test():
	n = int(input())
	a = list(input())
	b = list(input())
	c = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				c += 1
				a[i] = '2'
			elif i > 0 and a[i - 1] == '1':
				c += 1
				a[i - 1] = '2'
			elif i < n - 1 and a[i + 1] == '1':
				c += 1
				a[i + 1] = '2'
	print(c)
t = int(input())
while t:
	test()
	t -= 1


from sys import stdin
input = stdin.readline
t = int(input().rstrip())
for _ in range(t):
	n = int(input().rstrip())
	enemy = list(input().rstrip())
	Gregor = list(input().rstrip())
	ans = 0
	for i in range(n):
		if Gregor[i] == '1':
			if enemy[i] == '1' or enemy[i] is None:
				if i > 0 and enemy[i - 1] == '1':
					ans += 1
				elif i < n - 1 and enemy[i + 1] == '1':
					ans += 1
					enemy[i + 1] = None
			elif enemy[i] == '0':
				ans += 1
	print(ans)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	a1 = input()
	a = []
	otv = 0
	for i in a1:
		a.append(i)
	a1 = a.copy()
	a2 = input()
	a = []
	for i in a2:
		a.append(i)
	a2 = a.copy()
	for i in range(len(a1)):
		if a1[i] == '0':
			if a2[i] == '1':
				a2[i] = '0'
				otv += 1
		elif a1[i] == '1':
			if i == 0:
				if a2[1] == '1':
					a2[1] = '0'
					otv += 1
			elif i == n - 1:
				if a2[n - 2] == '1':
					a2[n - 2] = '0'
					otv += 1
			elif a2[i - 1] == '1':
				a2[i - 1] = '0'
				otv += 1
			elif a2[i + 1] == '1':
				a2[i + 1] = '0'
				otv += 1
	ans.append(otv)
for i in ans:
	print(i)


for _ in range(int(input())):
	n = int(input())
	s = list(input())
	t = list(input())
	ans = 0
	marked = [False] * n
	for i in range(n):
		if t[i] == '1':
			if i == 0:
				if s[i] == '0' and (not marked[i]):
					ans += 1
					marked[i] = True
				elif s[i + 1] == '1' and (not marked[i + 1]):
					ans += 1
					marked[i + 1] = True
			elif i == n - 1:
				if s[i] == '0' and (not marked[i]):
					ans += 1
					marked[i] = True
				elif s[i - 1] == '1' and (not marked[i - 1]):
					ans += 1
					marked[i - 1] = True
			elif s[i - 1] == '1' and (not marked[i - 1]):
				ans += 1
				marked[i - 1] = True
			elif s[i] == '0':
				ans += 1
				marked[i] = True
			elif s[i + 1] == '1' and (not marked[i + 1]):
				ans += 1
				marked[i + 1] = True
	print(ans)


for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	l1 = []
	l2 = []
	for i in s1:
		l1.append(int(i))
	for i in s2:
		l2.append(int(i))
	ans = 0
	if l1[0] == 0 and l2[0] == 1:
		ans += 1
	elif l1[1] == 1 and l2[0] == 1:
		ans += 1
		l1[1] = 2
	for i in range(1, n - 1):
		if l1[i] == 0 and l2[i] == 1:
			ans += 1
		elif l1[i - 1] == 1 and l2[i] == 1:
			ans += 1
			l1[i - 1] = 2
		elif l1[i + 1] == 1 and l2[i] == 1:
			ans += 1
			l1[i + 1] = 2
	if l1[-1] == 0 and l2[-1] == 1:
		ans += 1
	elif l1[-2] == 1 and l2[-1] == 1:
		ans += 1
		l1[-2] = 2
	print(ans)


import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None
		self.BUFSIZE = 8192

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def get_int():
	return int(input())

def get_ints():
	return list(map(int, input().split(' ')))

def get_int_grid(n):
	return [get_ints() for _ in range(n)]

def get_str():
	return input().strip()

def get_strs():
	return get_str().split(' ')

def flat_list(arr):
	return [item for subarr in arr for item in subarr]

def yes_no(b):
	if b:
		return 'YES'
	else:
		return 'NO'

def binary_search(good, left, right, delta=1, right_true=False):
	limits = [left, right]
	while limits[1] - limits[0] > delta:
		if delta == 1:
			mid = sum(limits) // 2
		else:
			mid = sum(limits) / 2
		if good(mid):
			limits[int(right_true)] = mid
		else:
			limits[int(~right_true)] = mid
	if good(limits[int(right_true)]):
		return limits[int(right_true)]
	else:
		return False

def prefix_sums(a):
	p = [0]
	for x in a:
		p.append(p[-1] + x)
	return p

def solve_a():
	p = get_int()
	if p == 5:
		return (2, 4)
	else:
		return (2, (p - 1) // 2)

def solve_b():
	n = get_int()
	enemy = list(get_str())
	me = list(get_str())
	cnt = 0
	for i in range(n):
		if me[i] == '1' and enemy[i] == '0':
			cnt += 1
		elif i > 0 and me[i] == '1' and (enemy[i - 1] == '1'):
			enemy[i - 1] = 'x'
			cnt += 1
		elif i < n - 1 and me[i] == '1' and (enemy[i + 1] == '1'):
			enemy[i + 1] = 'x'
			cnt += 1
	return cnt
t = get_int()
for _ in range(t):
	print(solve_b())


import os
import sys
from math import ceil, floor, sqrt, gcd, factorial
from io import BytesIO, IOBase
from collections import Counter
BUFSIZE = 8192

def main():
	for _ in range(int(input())):
		n = int(input())
		ene = list(input())
		g = list(input())
		count = 0
		for i in range(n):
			if g[i] == '1':
				if ene[i] == '0':
					count += 1
				elif i != 0 and ene[i - 1] == '1':
					count += 1
					ene[i - 1] = '0'
				elif i != n - 1 and ene[i + 1] == '1':
					count += 1
					ene[i + 1] = '0'
		print(count)

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import math

def solve(n, s1, s2):
	ans = 0
	for i in range(n):
		if s2[i] == '1':
			if s1[i] == '0':
				ans += 1
			elif i >= 1 and s1[i - 1] == '1':
				ans += 1
				s1[i - 1] = '2'
			elif i < n - 1 and s1[i + 1] == '1':
				ans += 1
				s1[i + 1] = '2'
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	print(solve(n, s1, s2))


t = int(input())
for _ in range(t):
	n = int(input())
	e = list(input())
	g = list(input())
	ans = 0
	for i in range(n):
		if g[i] == '1':
			if e[i] == '0':
				ans += 1
			elif i > 0 and e[i - 1] == '1':
				ans += 1
				e[i - 1] = '2'
			elif i < n - 1 and e[i + 1] == '1':
				ans += 1
				e[i + 1] = '2'
	print(ans)


def solve(n, a, b):
	ans = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				ans += 1
			elif i - 1 >= 0 and a[i - 1] == '1':
				ans += 1
			elif i + 1 < n and a[i + 1] == '1':
				ans += 1
				a[i + 1] = '-'
	return ans
t = int(input())
while t:
	n = int(input())
	a = list(input())
	b = list(input())
	print(solve(n, a, b))
	t -= 1


import os, sys
from io import BytesIO, IOBase
from math import log2, ceil, sqrt, gcd
from _collections import deque
import heapq as hp
from bisect import bisect_left, bisect_right
from math import cos, sin
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input()]
	b = [int(i) for i in input()]
	ans = 0
	x = y = 0
	for i in range(n):
		if a[i] == 1 and b[i] == 1:
			if x == 1 and y == 1:
				ans += 2
				x = 0
				y = 0
			elif x == 1:
				ans += 1
				x = 1
			else:
				x = y = 1
		elif a[i] == 0:
			x = 0
			y = 0
			if b[i] == 1:
				ans += 1
		elif a[i] == 1:
			if y == 1:
				ans += 1
				x = 0
				y = 0
			else:
				x = 1
				y = 0
	print(ans)


def f(opp, us, count=0, i=0):
	for i in range(len(opp)):
		if us[i] == '0':
			continue
		elif opp[i] == '0':
			count += 1
		elif i > 0 and opp[i - 1] == '1':
			count += 1
			opp[i - 1] = '*'
		elif i < len(opp) - 1 and opp[i + 1] == '1':
			count += 1
			opp[i + 1] = '*'
	print(count)
for _ in range(int(input())):
	n = int(input())
	opp = list(input())
	us = list(input())
	f(opp, us)


t = int(input())
while t:
	n = int(input())
	a = list(input())
	b = list(input())
	c = 0
	for i in range(0, n):
		if a[i] == '0' and b[i] == '1':
			b[i] = -1
			a[i] = -1
		elif b[i] == '1':
			if i == 0 and a[i + 1] == '1':
				a[i + 1] = -1
				b[i] = -1
			if i == n - 1 and a[i - 1] == '1':
				a[i - 1] = -1
				b[i] = -1
			if 0 < i < n - 1:
				if a[i - 1] == '1':
					a[i - 1] = -1
					b[i] = -1
				elif a[i + 1] == '1':
					a[i + 1] = -1
					b[i] = -1
	print(b.count(-1))
	t -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	enemy = [int(i) for i in input()]
	greg = [int(i) for i in input()]
	count = 0
	for i in range(n):
		if i == 0:
			if greg[i] == 1:
				if enemy[i] == 0:
					count += 1
				elif enemy[i + 1] == 1:
					count += 1
					enemy[i + 1] = 0
				else:
					pass
		elif i == n - 1:
			if greg[i] == 1:
				if enemy[i] == 0:
					count += 1
				elif enemy[i - 1] == 1:
					count += 1
					enemy[i - 1] = 0
		elif greg[i] == 1:
			if enemy[i] == 0:
				count += 1
			elif enemy[i - 1] == 1:
				count += 1
				enemy[i - 1] = 0
			elif enemy[i + 1] == 1:
				count += 1
				enemy[i + 1] = 0
	print(count)


def checkPossible(pos, enemy):
	if enemy[pos] == '0':
		return 1
	elif pos - 1 >= 0 and enemy[pos - 1] == '1':
		enemy[pos - 1] = '2'
		return 1
	elif pos + 1 <= len(enemy) - 1 and enemy[pos + 1] == '1':
		enemy[pos + 1] = '2'
		return 1
	else:
		return 0
t = int(input())
for CASE in range(t):
	n = int(input())
	enemy = input()
	me = input()
	enemy = [a for a in enemy]
	res = 0
	for i in range(n):
		if me[i] == '1':
			res += checkPossible(i, enemy)
	print(res)


for _ in range(int(input())):
	n = int(input())
	ans = int(0)
	en = list('2' + input() + '2')
	gr = list('2' + input() + '2')
	for i in range(1, n + 1):
		if gr[i] == '1':
			if en[i] == '0':
				ans += 1
			elif en[i - 1] == '1':
				ans += 1
				en[i - 1] = '2'
			elif en[i + 1] == '1':
				ans += 1
				en[i + 1] = '2'
	print(ans)


t = int(input())
for _ in range(0, t):
	c = 0
	n = int(input())
	h = [0] * n
	a = input()
	b = input()
	for i in range(0, n):
		if b[i] == '1':
			if a[i] == '0':
				c += 1
			elif i != 0 and a[i - 1] == '1' and (not h[i - 1]):
				c += 1
				h[i - 1] = 1
			elif i != n - 1 and a[i + 1] == '1' and (not h[i + 1]):
				c += 1
				h[i + 1] = 1
	print(c, end='\n')


k = []
for _ in range(int(input())):
	n = int(input())
	a = list(input(''))
	b = input('')
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				a[i] = '2'
			elif i != 0 and a[i - 1] == '1':
				a[i - 1] = '2'
			elif i != n - 1 and a[i + 1] == '1':
				a[i + 1] = '2'
	k.append(a.count('2'))
for i in k:
	print(i)


tinytales = int(input())
while tinytales:
	tinytales -= 1
	nobels = int(input())
	stationary1 = input()
	stationary2 = input()
	stationary1 = list(stationary1)
	stationary2 = list(stationary2)
	antrax = 0
	for icecream in range(0, nobels):
		if stationary2[icecream] == '0':
			continue
		if stationary1[icecream] == '0':
			antrax += 1
		elif icecream - 1 >= 0 and stationary1[icecream - 1] == '1':
			antrax += 1
			stationary1[icecream - 1] = '0'
		elif icecream + 1 < nobels and stationary1[icecream + 1] == '1':
			antrax += 1
			stationary1[icecream + 1] = '0'
	print(antrax)


t = int(input())
ans = []
for _ in range(t):
	n = int(input())
	u = list(input())
	v = list(input())
	ret = 0
	bn = n - 1
	for i in range(n):
		if v[i] == '1':
			if u[i] == '0':
				ret += 1
			elif i > 0 and u[i - 1] == '1':
				ret += 1
			elif i < bn and u[i + 1] == '1':
				u[i + 1] = '#'
				ret += 1
	ans.append(str(ret))
print('\n'.join(ans))


from bisect import insort, bisect_right, bisect_left
from sys import stdout, stdin, setrecursionlimit
from heapq import heappush, heappop, heapify
from io import BytesIO, IOBase
from collections import *
from itertools import *
from random import *
from string import *
from queue import *
from math import *
from re import *
from os import *

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, 8192))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
(graph, mod, szzz) = ({}, 10 ** 9 + 7, lambda : sorted(zzz()))

def getStr():
	return input()

def getInt():
	return int(input())

def listStr():
	return list(input())

def getStrs():
	return input().split()

def isInt(s):
	return '0' <= s[0] <= '9'

def input():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in input().split()]

def output(answer, end='\n'):
	stdout.write(str(answer) + end)

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def getPrimes(N=10 ** 5):
	SN = int(sqrt(N))
	sieve = [i for i in range(N + 1)]
	sieve[1] = 0
	for i in sieve:
		if i > SN:
			break
		if i == 0:
			continue
		for j in range(2 * i, N + 1, i):
			sieve[j] = 0
	prime = [i for i in range(N + 1) if sieve[i] != 0]
	return prime

def primeFactor(n, prime=getPrimes()):
	lst = []
	mx = int(sqrt(n)) + 1
	for i in prime:
		if i > mx:
			break
		while n % i == 0:
			lst.append(i)
			n //= i
	if n > 1:
		lst.append(n)
	return lst
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
daysInMounth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
num = getInt()
for _ in range(num):
	n = getInt()
	arr1 = listStr()
	arr2 = listStr()
	ans = 0
	mx = 0
	for i in range(n):
		x = arr1[i]
		y = arr2[i]
		if x == '0':
			if y == '1':
				ans += 1
				arr1[i] = '2'
			continue
		if y == '1':
			if i == 0:
				if arr1[i + 1] != '2' and arr1[i + 1] == '1':
					ans += 1
					arr1[i + 1] = '2'
			elif i < n - 1:
				if arr1[i - 1] == '1':
					ans += 1
					arr1[i - 1] = '2'
				elif arr1[i + 1] == '1':
					ans += 1
					arr1[i + 1] = '2'
			elif arr1[i - 1] == '1':
				ans += 1
				arr1[i - 1] = '2'
			elif arr1[i] == '0':
				ans += 1
				arr1[i] = '2'
	print(ans)


import sys
sys.setrecursionlimit(200000)
import math
from collections import Counter
from collections import defaultdict
from collections import deque
input = sys.stdin.readline
from functools import lru_cache
import heapq

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
testcases = inp()
for _ in range(testcases):
	n = inp()
	x = insr()
	y = insr()
	pawn = 0
	for i in range(len(x)):
		if y[i] == '0':
			continue
		if x[i] == '0':
			pawn += 1
			x[i] = '#'
		elif i - 1 >= 0 and x[i - 1] == '1':
			pawn += 1
		elif i + 1 < len(x) and x[i + 1] == '1':
			pawn += 1
			x[i + 1] = '#'
	print(pawn)


n = int(input())
a = []
for y in range(n):
	p = int(input())
	n1 = input()
	nn = input()
	summ = 0
	stop = -1
	for i in range(p):
		if nn[i] == '1':
			if (i >= 1 and n1[i - 1] == '1') and stop != i - 1:
				summ = summ + 1
			elif n1[i] == '0':
				summ = summ + 1
			elif i < p - 1 and n1[i + 1] == '1':
				summ = summ + 1
				stop = i + 1
	a.append(summ)
for y in range(n):
	print(a[y])


import math
import sys
import itertools
import fractions
wtf = sys.stdin.read()
wtf = wtf.strip().split('\n')
for t in [wtf[i:i + 3] for i in range(1, len(wtf), 3)]:
	n = int(t[0])
	r0 = [x for x in t[1]]
	rn = [x for x in t[2]]
	ans = 0
	for i in range(n):
		if rn[i] == '1':
			if r0[i] == '0':
				ans += 1
			elif i - 1 >= 0 and r0[i - 1] == '1':
				r0[i - 1] = '0'
				ans += 1
			elif i + 1 < n and r0[i + 1] == '1':
				r0[i + 1] = '0'
				ans += 1
	print(ans)


result = []
for _ in range(int(input())):
	n = int(input())
	you = [int(x) for x in input()]
	my = [int(x) for x in input()]
	occupy = set()
	cnt = 0
	for i in range(n):
		if my[i] == 1:
			if you[i] == 0:
				occupy.add(i)
				cnt += 1
			elif i > 0 and you[i - 1] == 1 and (i - 1 not in occupy):
				occupy.add(i - 1)
				cnt += 1
			elif i < n - 1 and you[i + 1] == 1:
				occupy.add(i + 1)
				cnt += 1
	result.append(cnt)
print(*result, sep='\n')


for _ in range(int(input())):
	n = int(input())
	a = ['X'] + list(input()) + ['X']
	m = 'X' + input() + 'X'
	ans = 0
	for i in range(1, n + 1):
		if m[i] == '1':
			if a[i] == '0':
				ans += 1
			elif a[i - 1] == '1':
				ans += 1
				a[i - 1] = '2'
			elif a[i + 1] == '1':
				ans += 1
				a[i + 1] = '2'
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	vr = list(input())
	greg = list(input())
	hr = 0
	for e in range(len(greg)):
		if greg[e] == '1':
			if vr[e] == '0':
				hr += 1
				vr[e] = '2'
			elif e > 0 and vr[e - 1] == '1':
				hr += 1
				vr[e - 1] = '2'
			elif e < n - 1 and vr[e + 1] == '1':
				hr += 1
				vr[e + 1] = '2'
	print(hr)


t = int(input())
for i in range(t):
	n = int(input())
	black = list(input())
	white = list(input())
	res = 0
	if white[0] == '1':
		if black[0] == '0':
			res += 1
		elif black[1] == '1':
			black[1] = '0'
			res += 1
	for i in range(1, n - 1):
		if white[i] == '1':
			if black[i] == '0':
				res += 1
			elif black[i - 1] == '1':
				black[i - 1] = '0'
				res += 1
			elif black[i + 1] == '1':
				black[i + 1] = '0'
				res += 1
	if white[n - 1] == '1':
		if black[n - 1] == '0':
			res += 1
		elif black[n - 2] == '1':
			black[n - 1] = '0'
			res += 1
	print(res)


for _ in range(int(input())):
	n = int(input())
	b = list(input())
	a = list(input())
	ans = 0
	for i in range(n):
		if a[i] == '1':
			if b[i] == '1':
				if i != 0:
					if b[i - 1] == '1':
						ans += 1
						b[i - 1] = '0'
						continue
				if i != n - 1:
					if b[i + 1] == '1':
						ans += 1
						b[i + 1] = '0'
						continue
			else:
				ans += 1
	print(ans)


ttt_ = int(input())
for __t in range(ttt_):
	n = int(input())
	tt = input()
	s = input()
	t = ['0'] * n
	for i in range(n):
		t[i] = tt[i]
	k = 0
	for i in range(n):
		if s[i] == '1':
			if t[i] == '0':
				k += 1
			elif i > 0 and t[i - 1] == '1':
				k += 1
			elif i < n - 1 and t[i + 1] == '1':
				k += 1
				t[i + 1] = '0'
	print(k)


for i in range(int(input())):
	n = int(input())
	s = list(input())
	l = list(input())
	ans = 0
	for i in range(n):
		if l[i] == '1':
			if s[i] == '0':
				ans += 1
			elif i != 0 and s[i - 1] == '1':
				s[i - 1] = '0'
				ans += 1
			elif i != n - 1 and s[i + 1] == '1':
				s[i + 1] = '0'
				ans += 1
	print(ans)


def solve(n, me, enemy):
	cnt = 0
	goal = [0] * n
	for i in range(n):
		if me[i] == '1':
			if i > 0 and enemy[i - 1] == '1' and (goal[i - 1] == 0):
				goal[i - 1] = 1
				cnt += 1
			elif enemy[i] == '0' and goal[i] == 0:
				goal[i] = 1
				cnt += 1
			elif i < n - 1 and enemy[i + 1] == '1' and (goal[i + 1] == 0):
				goal[i + 1] = 1
				cnt += 1
	return cnt

def main():
	ans = []
	t = int(input())
	for _ in range(t):
		n = int(input())
		enemy = input()
		me = input()
		ans.append(solve(n, me, enemy))
	for a in ans:
		print(a)
main()


t = int(input())
for p in range(t):
	n = int(input())
	en = input()
	en = [int(x) for x in en]
	us = input()
	us = [int(x) for x in us]
	op = 0
	for i in range(n):
		if us[i]:
			if not en[i]:
				op += 1
			elif en[i - 1] and i > 0:
				op += 1
			elif i < n - 1:
				if en[i + 1]:
					en[i + 1] = 0
					op += 1
	print(op)


def fun(n):
	if n == 5:
		print('2 4')
		print()
		return
	v = n - 1
	f = 2
	s = v // 2
	print(f, s, end=' ')
	print()
	return
for _ in range(int(input())):
	n = int(input())
	d = input()
	s = input()
	s = list(s)
	d = list(d)
	if s.count('1') == 0:
		print(0)
	elif d.count('1') == 0:
		print(s.count('1'))
	else:
		cnt = 0
		for i in range(n):
			if s[i] == '1' and d[i] == '0':
				cnt = cnt + 1
			elif s[i] == '1' and (d[i] == '1' or d[i] == '-1'):
				if i - 1 >= 0 and d[i - 1] == '1':
					d[i - 1] = '-1'
					cnt = cnt + 1
				elif i + 1 < n and d[i + 1] == '1':
					d[i + 1] = '-1'
					cnt = cnt + 1
		print(cnt)


T = int(input())
for t in range(T):
	n = int(input())
	grid = []
	ans = 0
	for i in range(2):
		x = input()
		x = [int(i) for i in x]
		grid.append(x)
	for i in range(n):
		if i > 0 and grid[1][i] == 1 and (grid[0][i - 1] == 1):
			grid[0][i - 1] = -1
		elif grid[1][i] == 1 and grid[0][i] == 0:
			grid[0][i] = -1
		elif i < n - 1 and grid[1][i] == 1 and (grid[0][i + 1] == 1):
			grid[0][i + 1] = -1
	print(grid[0].count(-1))


t = int(input())
for dummy_i in range(t):
	n = int(input())
	elis = input()
	e = [i for i in elis]
	m = input()
	eaten = set()
	for i in range(n):
		if m[i] == '1':
			if e[i] == '0':
				eaten.add(i)
			elif i != 0 and e[i - 1] == '1':
				eaten.add(i - 1)
				e[i - 1] = '-1'
			elif i != n - 1 and e[i + 1] == '1':
				eaten.add(i + 1)
				e[i + 1] = '-1'
	print(len(eaten))


t = int(input())
for i in range(t):
	n = int(input())
	ene = ['x'] + list(input()) + ['x']
	geo = ['x'] + list(input()) + ['x']
	ans = 0
	for j in range(1, n + 1):
		if geo[j] == '1':
			if ene[j] == '0':
				ans += 1
			elif ene[j - 1] == '1':
				ans += 1
				ene[j - 1] = '2'
			elif ene[j + 1] == '1':
				ans += 1
				ene[j + 1] = '2'
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input()]
	b = [int(i) for i in input()]
	ans = 0
	for i in range(n):
		if b[i] == 0:
			continue
		if a[i] == 0:
			ans += 1
		elif i != 0 and a[i - 1] == 1:
			ans += 1
			a[i - 1] = 2
		elif i < n - 1 and a[i + 1] == 1:
			ans += 1
			a[i + 1] = 2
	print(ans)


from math import *
from collections import defaultdict as dt
from sys import stdin
inp = lambda : stdin.readline().strip()
I = lambda : int(inp())
M = lambda : map(int, inp().split())
L = lambda : list(M())
mod = 1000000007
inf = 100000000000000000000
ss = 'abcdefghijklmnopqrstuvwxyz'

def solve():
	n = I()
	a = list('0' + inp() + '0')
	b = list('0' + inp() + '0')
	c = 0
	for i in range(1, n + 1):
		if a[i] == '0' and b[i] == '1':
			c = c + 1
		elif a[i] == '1' and b[i] == '1':
			if a[i - 1] == '1':
				c = c + 1
				a[i - 1] = '0'
			elif a[i + 1] == '1':
				c = c + 1
				a[i + 1] = '0'
	print(c)
tt = 1
tt = I()
for _ in range(tt):
	solve()


t = int(input())
for _ in range(t):
	n = int(input())
	ePawns = input()
	gPawns = input()
	indices = {}
	count = 0
	for i in range(n):
		if gPawns[i] != '0':
			if ePawns[i] == '0':
				count += 1
				indices[i] = False
			elif i - 1 >= 0 and ePawns[i - 1] == '1' and (i - 1 not in indices):
				count += 1
				indices[i - 1] = False
			elif i + 1 < n and ePawns[i + 1] == '1' and (i + 1 not in indices):
				count += 1
				indices[i + 1] = False
	print(count)


import sys
tokens = ''.join(sys.stdin.readlines()).split()[::-1]

def next():
	return tokens.pop()

def nextInt():
	return int(next())

def nextFloat():
	return float(next())

def getIntArray(n):
	return [nextInt() for _ in range(n)]

def getFloatArray(n):
	return [nextFloat() for _ in range(n)]

def getStringArray(n):
	return [next() for _ in range(n)]
flush = sys.stdout.flush
testcase = True

def solve(testcase=1):
	N = nextInt()
	(A, B) = (list(next()), list(next()))
	c = 0
	for i in range(N):
		if B[i] == '1':
			if A[i] == '0':
				c += 1
			elif i > 0 and A[i - 1] == B[i]:
				A[i - 1] = '0'
				c += 1
			elif i + 1 < N and A[i + 1] == B[i]:
				A[i + 1] = '0'
				c += 1
	print(c)
testcaseCount = nextInt() if testcase else 1
for tc in range(testcaseCount):
	solve(tc + 1)
assert not tokens


def solve():
	n = int(input())
	enemy = list(input())
	me = list(input())
	ans = 0
	for i in range(n):
		if me[i] == '1':
			if enemy[i] == '0':
				ans += 1
			elif i - 1 >= 0 and enemy[i - 1] == '1':
				ans += 1
				enemy[i - 1] = '0'
			elif i + 1 < n and enemy[i + 1] == '1':
				enemy[i + 1] = '0'
				ans += 1
	print(ans)
t = int(input())
for i in range(t):
	solve()


for t in range(int(input())):
	n = int(input())
	p = list(input())
	p = list(map(int, p))
	m = list(input())
	m = list(map(int, m))
	for i in range(n):
		if m[i] == 0:
			continue
		if i == 0:
			if p[0] == 0:
				m[i] = 0
				p[0] = 2
		if m[i] != 0 and i != 0 and (p[i - 1] == 1):
			m[i] = 0
			p[i - 1] = 2
		elif m[i] != 0 and p[i] == 0:
			m[i] = 0
			p[i] = 2
		elif m[i] != 0 and i + 1 < n and (p[i + 1] == 1):
			m[i] = 0
			p[i + 1] = 2
	print(p.count(2))


from collections import defaultdict, deque
import sys
input = lambda : sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a1 = input()
	b1 = input()
	a = ['2']
	b = ['2']
	for i in range(n):
		a.append(a1[i])
		b.append(b1[i])
	a.append('2')
	b.append('2')
	count = 0
	for i in range(1, n + 1):
		if b[i] == '1' and a[i] == '0':
			a[i] = '2'
			count += 1
		elif b[i] == '1' and a[i - 1] == '1':
			a[i - 1] = '2'
			count += 1
		elif b[i] == '1' and a[i + 1] == '1':
			a[i + 1] = '2'
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	captured = set()
	opp = input()
	me = input()
	result = 0
	for index in range(n):
		if me[index] == '1':
			if index > 0 and opp[index - 1] == '1' and (index - 1 not in captured):
				result += 1
			elif opp[index] == '0':
				result += 1
			elif index < n - 1 and opp[index + 1] == '1':
				result += 1
				captured.add(index + 1)
	print(result)


t = int(input())
for test in range(t):
	n = int(input())
	string1 = input()
	array1 = []
	for item in string1:
		array1.append(item)
	array2 = []
	string2 = input()
	for item in string2:
		array2.append(item)
	s = 0
	for i in range(n):
		if array2[i] == '1':
			if i - 1 >= 0 and array1[i - 1] == '1':
				array1[i - 1] = '2'
				s += 1
			elif array1[i] == '0':
				array1[i] = '2'
				s += 1
			elif i + 1 < n and array1[i + 1] == '1':
				array1[i + 1] = '2'
				s += 1
	print(s)


for _ in range(int(input())):
	n = int(input())
	arr = list(input())
	brr = list(input())
	for i in range(n):
		arr[i] = int(arr[i])
		brr[i] = int(brr[i])
	ans = 0
	dic = {}
	if brr[0] == 1:
		if arr[0] == 1:
			if arr[1] == 1:
				ans += 1
				dic[1] = 1
		else:
			ans += 1
			dic[0] = 1
	for i in range(1, n - 1):
		if brr[i] == 1:
			if arr[i] == 0 and i not in dic:
				ans += 1
				dic[i] = 1
			elif arr[i - 1] == 1 and i - 1 not in dic:
				ans += 1
				dic[i - 1] = 1
			elif arr[i + 1] == 1 and i + 1 not in dic:
				ans += 1
				dic[i + 1] = 1
	if brr[n - 1] == 1:
		if arr[n - 1] == 0 and n - 1 not in dic:
			ans += 1
		elif arr[n - 2] == 1 and n - 2 not in dic:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	enemy = input()
	gregor = input()
	dct = {a: 0 for a in range(n)}
	ans = 0
	dct[-1] = -1
	dct[n] = -1
	for i in range(n):
		if gregor[i] == '1':
			if enemy[i] == '0':
				ans += 1
			elif dct[i - 1] == 0:
				if enemy[i - 1] == '1':
					ans += 1
					dct[i - 1] = 1
				elif dct[i + 1] == 0:
					if enemy[i + 1] == '1':
						ans += 1
						dct[i + 1] = 1
			elif dct[i + 1] == 0:
				if enemy[i + 1] == '1':
					ans += 1
					dct[i + 1] = 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	m1 = list(map(int, input()))
	m2 = list(map(int, input()))
	ans = 0
	prev_set = False
	if m2[0]:
		if not m1[0]:
			ans += 1
		elif m1[1]:
			ans += 1
			m1[1] = 0
	prev_set = m1[0]
	for i in range(1, n):
		if m2[i]:
			if prev_set:
				ans += 1
			elif not m1[i]:
				ans += 1
			elif i + 1 < n and m1[i + 1]:
				ans += 1
				m1[i + 1] = 0
		prev_set = m1[i]
	print(ans)


t = int(input())
result = []
for i in range(t):
	n = int(input())
	enemy = list(map(int, input()))
	pawn = list(map(int, input()))
	count = 0
	for i in range(len(pawn)):
		if pawn[i] != 0:
			if enemy[i] == 0:
				enemy[i] = 2
				count += 1
			elif i == 0:
				if enemy[i + 1] == 1:
					count += 1
					enemy[i + 1] = 2
			elif i == n - 1:
				if enemy[i - 1] == 1:
					count += 1
					enemy[i - 1] = 2
			elif (enemy[i + 1] == 1) | (enemy[i - 1] == 1):
				if enemy[i - 1] == 1:
					count += 1
					enemy[i - 1] = 2
				elif enemy[i + 1] == 1:
					count += 1
					enemy[i + 1] = 2
	result.append(count)
for i in result:
	print(i)


t = int(input())
for _ in range(t):
	n = int(input())
	a = input()
	b = input()
	c = [True] * n
	o = 0
	if b[0] == '1' and a[0] == '0':
		o += 1
	elif b[0] == '1' and a[1] == '1':
		o += 1
		c[1] = False
	for i in range(1, n - 1):
		if b[i] == '1':
			if a[i] == '0':
				o += 1
			elif a[i - 1] == '1' and c[i - 1] == True:
				o += 1
				c[i - 1] = False
			elif a[i + 1] == '1' and c[i + 1] == True:
				o += 1
				c[i + 1] = False
	if b[n - 1] == '1' and a[n - 1] == '0':
		o += 1
	elif b[n - 1] == '1' and a[n - 2] == '1' and (c[n - 2] == True):
		o += 1
		c[n - 1] = False
	print(o)


for ii in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	a = list(map(int, a))
	b = list(map(int, b))
	c = 0
	if b[0]:
		if a[0] == 0:
			c += 1
			a[0] = 2
		elif a[1] == 1:
			c += 1
			a[1] = 2
	for jj in range(1, n - 1):
		if b[jj]:
			if a[jj] == 0:
				c += 1
				a[jj] = 2
			elif a[jj - 1] == 1:
				c += 1
				a[jj - 1] = 2
			elif a[jj + 1] == 1:
				c += 1
				a[jj + 1] = 2
	if b[-1]:
		if a[-1] == 0:
			c += 1
			a[-1] = 2
		elif a[-2] == 1:
			c += 1
			a[-2] = 2
	print(c)


t = int(input())

def sp():
	n = int(input())
	e1 = str(input())
	e = list(''.join(e1))
	g1 = str(input())
	g = list(''.join(g1))
	c = 0
	for i in range(len(g)):
		if i == 0:
			if g[i] == '1' and e[i] == '0':
				c += 1
				e[i] = '2'
			elif g[i] == '1' and e[i + 1] == '1':
				c += 1
				e[i + 1] = '2'
		elif i > 0 and i < n - 1:
			if g[i] == '1' and e[i] == '0':
				c += 1
				e[i] = '2'
			elif g[i] == '1' and e[i - 1] == '1':
				c += 1
				e[i - 1] = '2'
			elif g[i] == '1' and e[i + 1] == '1':
				c += 1
				e[i + 1] = '2'
		elif i == n - 1:
			if g[i] == '1' and e[i] == '0':
				c += 1
				e[i] = '2'
			elif g[i] == '1' and e[i - 1] == '1':
				c += 1
				e[i - 1] = '2'
	print(c)
for i in range(t):
	sp()


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=2 ** 51, func=lambda a, b: a & b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
for ik in range(int(input())):
	n = int(input())
	a = list(input())
	b = list(input())
	ans = 0
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				ans += 1
			elif i > 0 and a[i - 1] == '1':
				a[i - 1] = '0'
				ans += 1
			elif i < n - 1 and a[i + 1] == '1':
				a[i + 1] = '0'
				ans += 1
	print(ans)


def solve(first_row, curr_row):
	if curr_row.count(1) == 0:
		print(0)
		return
	n = len(first_row)
	if first_row.count(0) == n:
		print(curr_row.count(1))
	else:
		pawns = 0
		for i in range(n):
			if curr_row[i] == 0:
				continue
			elif first_row[i] == 0:
				pawns += 1
			elif i >= 1 and first_row[i - 1] == 1:
				pawns += 1
				first_row[i - 1] = -1
			elif i < n - 1 and first_row[i + 1] == 1:
				pawns += 1
				first_row[i + 1] = -1
		print(pawns)
	return
for _ in range(int(input())):
	n = int(input())
	first_row = list(input())
	curr_row = list(input())
	first_row = [int(x) for x in first_row]
	curr_row = [int(x) for x in curr_row]
	solve(first_row, curr_row)


t = int(input())
for ttt in range(t):
	n = int(input())
	a1 = input()
	a2 = input()
	aa1 = []
	aa2 = []
	for pro in range(n):
		aa1.append(a1[pro])
		aa2.append(a2[pro])
	ones = []
	ans = 0
	for k in range(n):
		if a1[k] == '1':
			ones.append(k)
		if a1[k] == '0' and a2[k] == '1':
			ans += 1
	i = 0
	if len(ones) > 1:
		while i < len(ones) - 1:
			if ones[i + 1] == ones[i] + 1:
				if aa2[ones[i]] == '1' and aa2[ones[i + 1]] == '1':
					ans += 2
					i += 2
				elif aa2[ones[i]] == '1' and aa2[ones[i + 1]] == '0':
					ans += 1
					i += 2
				elif aa2[ones[i]] == '0' and aa2[ones[i + 1]] == '1':
					ans += 1
					aa2[ones[i + 1]] = '0'
					i += 1
				else:
					i += 1
			else:
				i += 1
	print(ans)


def main():
	n = int(input())
	answer = []
	for i in range(n):
		answer.append(in_put())
	for i in range(n):
		print(answer[i])

def in_put():
	p = int(input())
	ans = 0
	x = list(input())
	y = list(input())
	for i in range(p):
		if y[i] == '1':
			if x[i] == '0':
				ans += 1
			elif i != 0 and x[i - 1] == '1':
				ans += 1
				x[i - 1] = '0'
			elif i != p - 1 and x[i + 1] == '1':
				ans += 1
				x[i + 1] = '0'
	return ans
main()


def game(l, li_1, li_2):
	n = 0
	li1 = []
	li2 = []
	for i in range(l):
		li1.append(int(li_1[i]))
		li2.append(int(li_2[i]))
	for i in range(l):
		if li2[i] == 1:
			if li1[i] == 0:
				li1[i] = 2
				n += 1
				continue
			if i - 1 >= 0 and li1[i - 1] == 1:
				li1[i - 1] = 2
				n += 1
				continue
			if i + 1 < l and li1[i + 1] == 1:
				li1[i + 1] = 2
				n += 1
				continue
	return n
n = int(input())
l = []
li1 = []
li2 = []
for i in range(n):
	l.append(int(input()))
	li1.append(input())
	li2.append(input())
for i in range(n):
	print(game(l[i], li1[i], li2[i]))


for _ in range(int(input())):
	n = int(input())
	b = list(input())
	a = list(input())
	visited = []
	count = 0
	if a[0] == '1':
		if b[0] == '0':
			count += 1
			b[0] = 'w'
		elif n > 1 and b[1] == '1':
			count += 1
			b[1] = 'w'
	for i in range(1, n - 1):
		if a[i] == '1':
			if b[i] == '0':
				count += 1
				b[i] = 'w'
			elif b[i - 1] == '1':
				count += 1
				b[i - 1] = 'w'
			elif b[i + 1] == '1':
				count += 1
				b[i + 1] = 'w'
	if a[n - 1] == '1' and n > 1:
		if b[n - 1] == '0':
			count += 1
			b[n - 1] = 'w'
		elif b[n - 2] == '1':
			count += 1
			b[n - 2] = 'w'
	print(count)


from sys import stdin
input = stdin.readline

def processPawns(ln, enemy, gregs):
	if '1' not in gregs:
		return 0
	count = 0
	for i in range(ln):
		if i == 0 and gregs[i] == '1':
			if gregs[i] == '1' and enemy[i] == '0':
				count += 1
				enemy[i] = '2'
			elif enemy[i] == '1' and ln > 1 and (enemy[i + 1] == '1'):
				count += 1
				enemy[i + 1] = '2'
		elif gregs[i] == '1':
			if enemy[i] == '0':
				count += 1
				enemy[i] = '2'
			elif enemy[i - 1] == '1':
				count += 1
				enemy[i - 1] = '2'
			elif i < ln - 1 and enemy[i + 1] == '1':
				count += 1
				enemy[i + 1] = '2'
	return count
n = int(input())
for _ in range(n):
	ln = int(input())
	enemy = list(input().strip())
	gregs = list(input().strip())
	print(processPawns(ln, enemy, gregs))


import sys
import bisect as bi
import collections as cc
import itertools as it
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
mod = 10 ** 9 + 7
for tc in range(int(input())):
	(n,) = I()
	first = list(input().strip())
	last = list(input().strip())
	ans = 0
	for i in range(n):
		if last[i] == '0':
			continue
		if first[i] == '0':
			ans += 1
		elif i > 0 and first[i - 1] == '1':
			ans += 1
		elif i < n - 1 and first[i + 1] == '1':
			first[i + 1] = '-'
			ans += 1
	print(ans)


answer = []
for _ in range(int(input())):
	n = int(input())
	s = [int(i) for i in input()]
	t = [int(i) for i in input()]
	ans = 0
	for i in range(n):
		if i == 0 and t[i] == 1:
			if s[i] == 0:
				ans += 1
				s[i] = 0
			elif i + 1 < n and s[i + 1] == 1:
				ans += 1
				s[i + 1] = 0
		elif i > 0 and i < n - 1 and (t[i] == 1):
			if s[i] == 0:
				ans += 1
				s[i] = 0
			elif s[i - 1] == 1:
				ans += 1
				s[i - 1] = 0
			elif s[i + 1] == 1:
				ans += 1
				s[i + 1] = 0
		elif i == n - 1 and t[i] == 1:
			if s[i] == 0:
				ans += 1
				s[i] = 0
			elif i - 1 > -1 and s[i - 1] == 1:
				ans += 1
				s[i - 1] = 0
	answer.append(ans)
for i in answer:
	print(i)


t = int(input())
answer = []
for i in range(t):
	n = int(input())
	enemy = list(input())
	gregor = list(input())
	count = 0
	for p in range(n):
		if enemy[p] == '0' and gregor[p] == '1':
			gregor[p] = '0'
			count += 1
	for b in range(n):
		if enemy[b] == '1':
			if b == 0:
				if gregor[b + 1] == '1':
					count += 1
					gregor[b + 1] = '0'
			elif b == n - 1:
				if gregor[b - 1] == '1':
					count += 1
					gregor[b - 1] == '0'
			elif gregor[b - 1] == '1':
				count += 1
				gregor[b - 1] = '0'
			elif gregor[b + 1] == '1':
				count += 1
				gregor[b + 1] = '0'
	answer.append(count)
for item in answer:
	print(item)


import sys
input = sys.stdin.readline

def inp():
	return int(input())

def input_list():
	return list(map(int, input().split()))

def input_string():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
tests = inp()
for _ in range(tests):
	size = inp()
	enemy = input_string()
	geo = input_string()
	passed = 0
	for i in range(size):
		e = enemy[i]
		g = geo[i]
		if e == '0' and g == '1':
			passed += 1
		elif e == '1' and g == '1':
			if i >= 1 and enemy[i - 1] == '1':
				enemy[i - 1] = '0'
				passed += 1
			elif i < size - 1 and enemy[i + 1] == '1':
				enemy[i + 1] = '0'
				passed += 1
	print(passed)


t = int(input())
result = []
for i in range(t):
	r = 0
	n = int(input())
	a = input()
	b = input()
	e = [int(x) for x in str(a)]
	h = [int(x) for x in str(b)]
	for j in range(n):
		if e[j] == 0 and h[j] == 1:
			r += 1
			continue
		elif j != 0 and h[j] == 1 and (e[j - 1] == 1):
			r += 1
			e[j - 1] = 0
			continue
		elif j != n - 1 and h[j] == 1 and (e[j + 1] == 1):
			r += 1
			e[j + 1] = 0
			continue
	result.append(r)
for i in result:
	print(i)


import math
from heapq import heappush, heappop, heapify
import random
import string
from collections import deque
from bisect import bisect, bisect_left, bisect_right, insort
import sys
input = sys.stdin.readline
S = lambda : input().rstrip()
I = lambda : int(S())
M = lambda : map(int, S().split())
L = lambda : list(M())
H = 1000000000 + 7
for _ in range(I()):
	n = I()
	s1 = S()
	s2 = S()
	d = {}
	c = 0
	for i in range(n):
		if s2[i] == '1':
			if i - 1 >= 0 and s1[i - 1] == '1' and (d.get(i - 1, 0) == 0):
				c += 1
				d[i - 1] = 1
			elif s1[i] == '0':
				c += 1
			elif i + 1 < n and s1[i + 1] == '1' and (d.get(i + 1, 0) == 0):
				c += 1
				d[i + 1] = 1
	print(c)


import sys, threading, heapq, math
from collections import defaultdict, Counter
input = sys.stdin.readline

def main():
	for _ in range(int(input())):
		n = int(input())
		enemy = input().strip()
		gregor = input().strip()
		count = 0
		visited = set()
		for i in range(n):
			if gregor[i] == '1':
				if enemy[i] == '0':
					count += 1
				elif i > 0 and enemy[i - 1] == '1' and (i - 1 not in visited):
					count += 1
					visited.add(i - 1)
				elif i < n - 1 and enemy[i + 1] == '1' and (i + 1 not in visited):
					count += 1
					visited.add(i + 1)
		print(count)
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	s1 = input()
	s2 = input()
	arr = []
	for c in s1:
		arr.append(c)
	ans = 0
	for i in range(n):
		if s2[i] == '1':
			if i > 0 and arr[i - 1] == '1':
				arr[i - 1] = '0'
				ans += 1
				continue
			elif arr[i] == '0':
				ans += 1
				continue
			elif i < n - 1 and arr[i + 1] == '1':
				arr[i + 1] = '0'
				ans += 1
				continue
	print(ans)


for t in range(int(input())):
	n = int(input())
	A = list(input())
	B = list(input())
	ans = 0
	for i in range(n):
		if B[i] == '1':
			if A[i] == '0':
				ans += 1
			elif i >= 1 and A[i - 1] == '1':
				ans += 1
				A[i - 1] = '0'
			elif i < n - 1 and A[i + 1] == '1':
				ans += 1
				A[i + 1] = '0'
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	enemey = str(input())
	gregor = str(input())
	ans_arr = [0 for i in range(n)]
	for i in range(n):
		if gregor[i] == '1':
			if enemey[i] == '0':
				ans_arr[i] = 1
			elif i == 0:
				if enemey[i + 1] == '1' and ans_arr[i + 1] != 1:
					ans_arr[i + 1] = 1
			elif i == n - 1:
				if enemey[i - 1] == '1' and ans_arr[i - 1] != 1:
					ans_arr[i - 1] = 1
			elif enemey[i - 1] == '1' and ans_arr[i - 1] != 1:
				ans_arr[i - 1] = 1
			elif enemey[i + 1] == '1' and ans_arr[i + 1] != 1:
				ans_arr[i + 1] = 1
	print(ans_arr.count(1))


def main():
	t = int(input())
	anst = []
	for _ in range(t):
		n = int(input())
		v = list(map(int, input()))
		g = list(map(int, input()))
		ans = 0
		for num in range(n):
			flag = 0
			if g[num] == 1:
				if v[num] == 0:
					flag = 1
				elif num != 0 and (not flag) and (v[num - 1] == 1):
					v[num - 1] = -1
					flag = 1
				elif num != n - 1 and (not flag) and (v[num + 1] == 1):
					v[num + 1] = -1
					flag = 1
			ans += flag
		anst.append(ans)
	for _ in anst:
		print(_)
main()


import sys, os.path
sys.setrecursionlimit(200000)
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r+')
	sys.stdout = open('output.txt', 'w')
from collections import defaultdict
from math import ceil
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ans = 0
	v = [0] * (n + 1)
	for i in range(n):
		if b[i] == '1':
			if a[i] == '0':
				ans += 1
				v[i] = 1
			elif i > 0 and a[i - 1] == '1' and (v[i - 1] == 0):
				ans += 1
				v[i - 1] = 1
			elif i < n - 1 and a[i + 1] == '1' and (v[i + 1] == 0):
				ans += 1
				v[i + 1] = 1
	v1 = [0] * (n + 1)
	ans1 = 0
	for i in range(n - 1, -1, -1):
		if b[i] == '1':
			if a[i] == '0':
				ans1 += 1
				v1[i] = 1
			elif i > 0 and a[i - 1] == '1' and (v1[i - 1] == 0):
				ans1 += 1
				v1[i - 1] = 1
			elif i < n - 1 and a[i + 1] == '1' and (v1[i + 1] == 0):
				ans1 += 1
				v1[i + 1] = 1
	print(max(ans, ans1))


t = int(input())
while t > 0:
	n = int(input())
	enemy = input()
	l_enemy = [int(x) for x in enemy]
	player = input()
	l_player = [int(x) for x in player]
	board = [l_enemy, l_player]
	i = 1
	count = 0
	for j in range(n):
		if board[i][j] == 1:
			if board[i - 1][j] == 0:
				count += 1
				board[i - 1][j] = -1
			else:
				if j == 0:
					if board[i - 1][1] == 1:
						count += 1
						board[i - 1][1] = -1
					continue
				if j == n - 1:
					if board[i - 1][j - 1] == 1:
						count += 1
						board[i - 1][j - 1] = -1
					continue
				if board[i - 1][j - 1] == 1:
					count += 1
					board[i - 1][j - 1] = -1
				elif board[i - 1][j + 1] == 1:
					count += 1
					board[i - 1][j + 1] = -1
	print(count)
	t -= 1


t = int(input())
games = [[int(input()), input(), input()] for _ in range(t)]
answer = []
for k in range(t):
	count = 0
	visited = [False] * games[k][0]
	for i in range(games[k][0]):
		if '1' == games[k][2][i]:
			if '0' == games[k][1][i]:
				count += 1
			elif 0 <= i - 1 and '1' == games[k][1][i - 1] and (not visited[i - 1]):
				visited[i - 1] = True
				count += 1
			elif i + 1 < games[k][0] and '1' == games[k][1][i + 1] and (not visited[i + 1]):
				visited[i + 1] = True
				count += 1
	answer.append(count)
answer = '\n'.join(map(str, answer))
print(answer)


for _ in range(int(input())):
	n = int(input())
	s = input()
	t = input()
	vis = set()
	ans = 0
	if s[0] == '0' and t[0] == '1':
		ans += 1
	elif s[1] == '1' and t[0] == '1' and (1 not in vis):
		ans += 1
		vis.add(1)
	for i in range(1, n - 1):
		if s[i] == '0' and t[i] == '1':
			ans += 1
		elif s[i] == '1' and t[i] == '1':
			if s[i - 1] == '1' and t[i] == '1' and (i - 1 not in vis):
				ans += 1
				vis.add(i - 1)
			elif s[i + 1] == '1' and t[i] == '1' and (i + 1 not in vis):
				ans += 1
				vis.add(i + 1)
	if s[n - 1] == '0' and t[n - 1] == '1':
		ans += 1
	elif s[n - 2] == '1' and t[n - 1] == '1' and (n - 2 not in vis):
		ans += 1
		vis.add(n - 2)
	print(ans)


import math

def intlist():
	return [int(i) for i in input().split(' ')]

def stringlist():
	return input().split(' ')

def yes(t):
	if t:
		return 'YES'
	return 'NO'

def printjoin(l, str=False):
	if str:
		l = [str(i) for i in l]
	return ' '.join(l)

def power_of_two(n):
	b = bin(n)[2:]
	return int(b) == 10 ** (len(b) - 1)

def bit_count(n):
	return bin(n).count('1')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	lcm = x * y // gcd(x, y)
	return lcm

def isint(str):
	try:
		int(str)
		return True
	except ValueError:
		return False

def solve():
	n = int(input())
	a = list(input())
	b = list(input())
	ans = 0
	for i in range(n):
		if b[i] != '1':
			continue
		if i != 0 and a[i - 1] == '1':
			a[i - 1] = '2'
			ans += 1
		elif a[i] == '0':
			a[i] == '2'
			ans += 1
		elif i != n - 1 and a[i + 1] == '1':
			a[i + 1] = '2'
			ans += 1
	return ans
t = input()
for tt in range(int(t)):
	print(solve())


from __future__ import division, print_function
import os, sys
import math
import random
import collections
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

class my_dictionary(dict):

	def __init__(self):
		self = dict()

	def add(self, key, value):
		self[key] = value

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().strip().split(' '))

def msi():
	return map(str, input().strip().split(' '))

def li():
	return list(mi())

def sli():
	return list(msi())

def dmain():
	sys.setrecursionlimit(100000000)
	threading.stack_size(40960000)
	thread = threading.Thread(target=main)
	thread.start()
abc = 'abcdefghijklmnopqrstuvwxyz'
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def getKey(item):
	return item[1]

def sort2(l):
	return sorted(l, key=getKey, reverse=True)

def d2(n, m, num):
	return [[num for x in range(m)] for y in range(n)]

def isPowerOfTwo(x):
	return x and (not x & x - 1)

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def ntl(n):
	return [int(i) for i in str(n)]

def factorial(n):
	return 1 if n == 1 or n == 0 else n * factorial(n - 1)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(n - r))

def binary_search(arr, low, high, r, l, c):
	if high >= low:
		mid = (high + low) // 2
		if arr[mid] <= r or arr[mid] >= l:
			c += 1
		elif arr[mid] > r:
			return binary_search(arr, low, mid - 1, r, l, c)
		else:
			return binary_search(arr, mid + 1, high, r, l, c)
	else:
		return c

def ceil(x, y):
	if x % y == 0:
		return x // y
	else:
		return x // y + 1

def powerMod(x, y, p):
	res = 1
	x %= p
	while y > 0:
		if y & 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def nCr(n, r):
	return fact(n) / (fact(r) * fact(n - r))

def fact(n):
	res = 1
	for i in range(2, n + 1):
		res = res * i
	return res

def printDivisors(n):
	i = 1
	count = 0
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				count += 1
			else:
				count += 1
		i = i + 1
	return count

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def read():
	sys.stdin = open('tessst.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def padded_bin_with_complement(x):
	if x < 0:
		return bin(2 ** 16 - abs(x))[2:].zfill(16)
	else:
		return bin(x)[2:].zfill(16)

def binaryToDecimal(binary):
	binary1 = binary
	(decimal, i, n) = (0, 0, 0)
	while binary != 0:
		dec = binary % 10
		decimal = decimal + dec * pow(2, i)
		binary = binary // 10
		i += 1
	return decimal

def CountFrequency(my_list):
	freq = {}
	for item in my_list:
		if item in freq:
			freq[item] += 1
		else:
			freq[item] = 1
	return freq

def pos(a):
	b = [0] * len(a)
	c = sorted(a)
	for i in range(len(a)):
		for j in range(len(a)):
			if c[j] == a[i]:
				b[i] = j
				break
	return b

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def commonn(a, b, n):
	c = []
	for i in range(n):
		if a[i] == b[i]:
			c.append('-1')
		else:
			c.append(b[i])
	return c

def find_lcm(num1, num2):
	if num1 > num2:
		num = num1
		den = num2
	else:
		num = num2
		den = num1
	rem = num % den
	while rem != 0:
		num = den
		den = rem
		rem = num % den
	gcd = den
	lcm = int(int(num1 * num2) / int(gcd))
	return lcm

def sumdigit(n):
	n = str(n)
	k = 0
	for i in range(len(n)):
		k += int(n[i])
	return k

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z
from itertools import permutations

def isPerfectSquare(x):
	if x >= 0:
		sr = math.sqrt(x)
		return sr * sr == x
	return False

def knapSack(W, wt, val, n):
	K = [[0 for x in range(W + 1)] for x in range(n + 1)]
	for i in range(n + 1):
		for w in range(W + 1):
			if i == 0 or w == 0:
				K[i][w] = 0
			elif wt[i - 1] <= w:
				K[i][w] = max(val[i - 1] + K[i - 1][w - wt[i - 1]], K[i - 1][w])
			else:
				K[i][w] = K[i - 1][w]
	return K[n][W]
from collections import Counter

class Node:

	def __init__(self, val):
		self.next = None
		self.data = val

class linkedList:

	def __init__(self):
		self.head = None
		self.tail = None

	def add(self, num):
		if self.head is None:
			self.head = Node(num)
			self.tail = self.head
		else:
			self.tail.next = Node(num)
			self.tail = self.tail.next

	def isLoop(self):
		if self.head is None:
			return False
		slow = self.head
		fast = self.head.next
		slow = slow.next
		fast = fast.next.next
		while slow != fast:
			if fast is None or fast.next == None:
				return False
			fast = fast.next.next
			slow = slow.next
		return True

	def loopHere(self, pos):
		if pos == 0:
			return
		walk = self.head
		for _ in range(1, pos):
			walk = walk.next
		self.tail.next = walk

	def length(self):
		walk = self.head
		c = 0
		while walk:
			c += 1
			walk = walk.next
		return c
from heapq import heappop, heappush, heapify

def sort_k(arr, n, k):
	heap = arr[:k + 1]
	heapify(heap)
	target_index = 0
	for rem_elmnts_index in range(k + 1, n):
		arr[target_index] = heappop(heap)
		heappush(heap, arr[rem_elmnts_index])
		target_index += 1
	while heap:
		arr[target_index] = heappop(heap)
		target_index += 1
import string

def main():
	for _ in range(int(input())):
		n = ii()
		b = si()
		a = si()
		visited = {}
		count = 0
		for i in range(n):
			if a[i] == '0':
				continue
			if i == 0:
				if b[i] == '0':
					count += 1
				elif b[i + 1] == '1':
					count += 1
					visited[i + 1] = 1
			elif i == n - 1:
				if b[i] == '0':
					count += 1
				elif b[i - 1] == '1' and i - 1 not in visited:
					count += 1
					visited[i - 1] = 1
			elif a[i] == '1' and b[i] == '0':
				count += 1
			elif a[i] == '1' and (b[i - 1] == '1' or b[i + 1] == '1'):
				if b[i - 1] == '1' and i - 1 not in visited:
					count += 1
					visited[i - 1] = 1
				elif b[i + 1] == '1' and i + 1 not in visited:
					count += 1
					visited[i + 1] = 1
		print(count)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


for _ in range(int(input())):
	n = int(input())
	a = str(input())
	b = str(input())
	dem = 0
	cnt = [0] * (n + 1)
	for i in range(0, len(a)):
		if b[i] == '1':
			if i == 0:
				if a[i] == '0':
					dem += 1
				elif a[i + 1] == '1' and cnt[i + 1] == 0:
					cnt[i + 1] = 1
					dem += 1
			elif i == n - 1:
				if a[i] == '0':
					dem += 1
				elif a[i - 1] == '1' and cnt[i - 1] == 0:
					cnt[i - 1] = 1
					dem += 1
			elif a[i] == '0':
				dem += 1
			elif a[i - 1] == '1' and cnt[i - 1] == 0:
				cnt[i - 1] = 1
				dem += 1
			elif a[i + 1] == '1' and cnt[i + 1] == 0:
				cnt[i + 1] = 1
				dem += 1
	print(dem)


t = int(input())
while t != 0:
	n = int(input())
	s1 = list(input())
	s2 = list(input())
	c = 0
	if s2[0] == '1':
		if s1[0] == '0':
			c = c + 1
		elif s1[1] == '1':
			c = c + 1
			s1[1] = '0'
	for i in range(1, n - 1):
		if s2[i] == '1':
			if s1[i] == '0':
				c = c + 1
			elif s1[i - 1] == '1':
				s1[i - 1] = '0'
				c = c + 1
			elif s1[i + 1] == '1':
				c = c + 1
				s1[i + 1] = '0'
	if s2[n - 1] == '1':
		if s1[n - 1] == '0':
			c = c + 1
		elif s1[n - 2] == '1':
			c = c + 1
			s1[n - 2] = '0'
	print(c)
	t = t - 1


for _ in range(int(input())):
	n = int(input())
	v = input()
	s = input()
	s = '0' + s + '0'
	v = '0' + v + '0'
	en = ['0'] * len(v)
	for i in range(len(v)):
		en[i] = v[i]
	ans = 0
	for i in range(1, n + 2):
		if s[i] == '1':
			if en[i - 1] == '1':
				ans += 1
			elif en[i] == '0':
				ans += 1
			elif en[i + 1] == '1':
				en[i + 1] = '2'
				ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = input()
	b = input()
	ar1 = []
	ar2 = []
	c = 0
	for i in range(n):
		ar1.append(int(a[i]))
		ar2.append(int(b[i]))
	for i in range(n):
		if i == 0:
			if ar2[i] == 1:
				if ar1[i] == 0:
					ar1[i] = None
					c += 1
				elif ar1[i + 1] == 1:
					ar1[i + 1] = None
					c += 1
		elif i == n - 1:
			if ar2[i] == 1:
				if ar1[i] == 0:
					ar1[i] = None
					c += 1
				elif ar1[i - 1] == 1:
					ar1[i - 1] = None
					c += 1
		elif ar2[i] == 1:
			if ar1[i] == 0:
				ar1[i] = None
				c += 1
			elif ar1[i - 1] == 1:
				ar1[i - 1] = None
				c += 1
			elif ar1[i + 1] == 1:
				ar1[i + 1] = None
				c += 1
	print(c)


for _ in range(int(input())):
	n = int(input())
	en = input()
	gr = input()
	l1 = [-1]
	l2 = [-1]
	for i in range(n):
		l1.append(int(en[i]))
		l2.append(int(gr[i]))
	count = 0
	l1.append(-1)
	l2.append(-1)
	for i in range(1, n + 1):
		if l2[i] == 1:
			if l1[i] == 0:
				count += 1
				l1[i] = -1
			elif l1[i - 1] == 1:
				count += 1
				l1[i - 1] == -1
			elif l1[i + 1] == 1:
				count += 1
				l1[i + 1] = -1
	print(count)


import sys
input = sys.stdin.readline

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		ep = list(map(int, input().strip()))
		yp = list(map(int, input().strip()))
		ans = 0
		for i in range(n):
			if yp[i] == 1:
				if ep[i] == 0:
					ans += 1
					continue
				if i >= 1 and ep[i - 1] == 1:
					ep[i - 1] = 0
					ans += 1
					continue
				elif i < n - 1 and ep[i + 1] == 1:
					ep[i + 1] = 0
					ans += 1
					continue
		print(ans)
main()


def solution(enemy, my):
	res = 0
	for i in range(len(my)):
		if my[i] == '1':
			if enemy[i] == '0':
				res += 1
				enemy[i] = '2'
			elif i > 0 and enemy[i - 1] == '1':
				res += 1
				enemy[i - 1] = '2'
			elif i + 1 < len(my) and enemy[i + 1] == '1':
				enemy[i + 1] = '2'
				res += 1
	return res
n = int(input())
for _ in range(n):
	num = int(input())
	enemy = list(input())
	my = list(input())
	print(solution(enemy, my))


for _ in range(int(input())):
	n = int(input())
	black = list(input())
	white = list(input())
	ans = 0
	for i in range(n):
		if white[i] == '1' and black[i] == '0':
			ans += 1
			white[i] = '0'
	w = True
	while w:
		l = 0
		for i in range(n):
			if white[i] == '1':
				if i + 1 < n and i - 1 >= 0:
					if black[i + 1] == '1' and black[i - 1] == '1':
						continue
					else:
						white[i] = '0'
						if black[i + 1] == '1':
							black[i + 1] = '0'
							l = 1
							ans += 1
						elif black[i - 1] == '1':
							black[i - 1] = '0'
							l = 1
							ans += 1
				else:
					if i + 1 < n and black[i + 1] == '1':
						white[i] = '0'
						black[i + 1] = '0'
						l = 1
						ans += 1
					if i - 1 >= 0 and black[i - 1] == '1':
						white[i] = '0'
						black[i - 1] = '0'
						l = 1
						ans += 1
		if l == 0:
			w = False
			for i in range(n):
				if white[i] == '1':
					if i + 1 < n and black[i + 1] == '1' or (i - 1 >= 0 and black[i - 1] == '1'):
						ans += 1
	print(ans)


from collections import *
from math import *
TT = int(input())
for y in range(TT):
	n = int(input())
	s1 = input()
	s2 = input()
	vis = [0] * n
	ans = 0
	for i in range(n):
		if s2[i] == '1':
			if s1[i] == '0':
				ans += 1
			elif i - 1 >= 0 and s1[i - 1] == '1' and (vis[i - 1] == 0):
				ans += 1
				vis[i - 1] = 1
			elif i + 1 < n and s1[i + 1] == '1' and (vis[i + 1] == 0):
				ans += 1
				vis[i + 1] = 1
	print(ans)


from sys import *
input = stdin.readline
from bisect import *
import math
from collections import *
import operator
from heapq import *
from itertools import *
inf = 10 ** 18
mod = 10 ** 9 + 7
for _ in range(int(input())):
	n = int(input())
	mat = []
	for _ in range(2):
		row = list(input())[:-1]
		mat.append(row)
	che = [0] * n
	vis = [0] * n
	cnt = 0
	for i in range(n):
		if mat[1][i] == '1':
			if i > 0 and mat[0][i - 1] == '1' and (che[i - 1] == 0):
				vis[i] = 1
				che[i - 1] = 1
				cnt += 1
			elif mat[0][i] == '0' and che[i] == 0:
				che[i] = 1
				vis[i] = 1
				cnt += 1
			elif i < n - 1 and mat[0][i + 1] == '1' and (che[i + 1] == 0):
				vis[i] = 1
				che[i + 1] = 1
				cnt += 1
	print(cnt)


num = int(input())
for i in range(num):
	n = int(input())
	vrag = list(input())
	gregor = list(input())
	kol = 0
	for i in range(n):
		if gregor[i] == '1':
			if vrag[i] == '0':
				kol += 1
			elif i >= 1:
				if vrag[i - 1] == '1':
					kol += 1
					vrag[i - 1] = 0
				elif i + 1 <= n - 1:
					if vrag[i + 1] == '1':
						kol += 1
						vrag[i + 1] = 0
			elif vrag[i + 1] == '1':
				kol += 1
				vrag[i + 1] = 0
	print(kol)