#P1549B. Gregor and the Pawn Game

    ID: 6002 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>dfs and similardpflowsgraph matchingsgraphsgreedyimplementation*800

Gregor and the Pawn Game

No submission language available for this problem.

Description

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

Currently, Gregor has some pawns in the nn-th row. There are also enemy pawns in the 11-st row. On one turn, Gregor moves one of his pawns. A pawn can move one square up (from (i,j)(i,j) to (i1,j)(i-1,j)) if there is no pawn in the destination square. Additionally, a pawn can move one square diagonally up (from (i,j)(i,j) to either (i1,j1)(i-1,j-1) or (i1,j+1)(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 11?

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

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

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

The second line consists of a string of binary digits of length nn, where a 11 in the ii-th position corresponds to an enemy pawn in the ii-th cell from the left, and 00 corresponds to an empty cell.

The third line consists of a string of binary digits of length nn, where a 11 in the ii-th position corresponds to a Gregor's pawn in the ii-th cell from the left, and 00 corresponds to an empty cell.

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

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

Input

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

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

The second line consists of a string of binary digits of length nn, where a 11 in the ii-th position corresponds to an enemy pawn in the ii-th cell from the left, and 00 corresponds to an empty cell.

The third line consists of a string of binary digits of length nn, where a 11 in the ii-th position corresponds to a Gregor's pawn in the ii-th cell from the left, and 00 corresponds to an empty cell.

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

Output

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

Samples

Sample Input 1

4
3
000
111
4
1111
1111
3
010
010
5
11001
00000

Sample Output 1

3
4
0
0

Note

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

In the second example, Gregor can guarantee that all 44 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 00.