CF BUDDY
← Problems·

1680E · Moving Chips

2000 · bitmasks, dp, greedy

Problem: You are given a board of size 2×n2 \times n (22 rows, nn columns). Some cells of the board contain chips. The chip is represented as '*', and an empty space is represented as '.'. It is guaranteed that there is at least one chip on the board.

In one move, you can choose any chip and move it to any adjacent (by side) cell of the board (if this cell is inside the board). It means that if the chip is in the first row, you can move it left, right or down (but it shouldn't leave the board). Same, if the chip is in the second row, you can move it left, right or up.

If the chip moves to the cell with another chip, the chip in the destination cell disappears (i. e. our chip captures it).

Your task is to calculate the minimum number of moves required to leave exactly one chip on the board.

You have to answer tt independent test cases.

Input Format: 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.

The first line of the test case contains one integer nn (1n21051 \le n \le 2 \cdot 10^5) — the length of the board. The second line of the test case contains the string s1s_1 consisting of nn characters '' (chip) and/or '.' (empty cell). The third line of the test case contains the string s2s_2 consisting of nn characters '' (chip) and/or '.' (empty cell).

Additional constraints on the input:

  • in each test case, there is at least one chip on a board;
  • the sum of nn over all test cases does not exceed 21052 \cdot 10^5 (n2105\sum n \le 2 \cdot 10^5).

Output Format: For each test case, print one integer — the minimum number of moves required to leave exactly one chip on the board.

Sample Cases

Case 1

Input

5
1
*
.
2
.*
**
3
*.*
.*.
4
**.*
**..
5
**...
...**

Output

0
2
3
5
5

Similar problems

00:00:00
Loading editor…
Welcome! I'm your coding tutor for this problem. Use the chips below to reveal stored hints or get AI feedback on your code. I'll guide you step by step — never giving away the solution.

Sign in to unlock AI tutor feedback