CF-2272B•Codeforces

Frogs Jump

constructive algorithmsgreedy

Given a 2×n2 \times n grid, each cell of the grid is either empty or contains one frog. It is guaranteed that each column of the input grid contains at least one frog. You can choose kk frogs and remove them from the grid. After this, all remaining frogs will jump.

Each frog can jump up, down, left, or right by 11 cell, but cannot jump outside the grid. All frogs must choose a legal direction and jump simultaneously exactly once. After jumping, the number of frogs in each row and each column of the grid must remain unchanged.

Note that:

  • Even if two frogs' jump directions conflict, they can still jump to their respective target cells.
  • Multiple frogs are allowed to jump to the same cell, because a cell can hold arbitrarily many frogs.

Find the minimum kk such that there exists a valid jumping scheme.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤1041 \le t \le 10^4). The description of the test cases follows.

For each test case, the first line contains a single integer nn (1≤n≤2⋅1051 \le n \le 2 \cdot 10^5), where nn is the number of columns in the grid.

The next two lines each contain a string of length nn; we use the character f\texttt{f} to represent a cell containing a frog, and the character o\texttt{o} to represent an empty cell.

It is guaranteed that each column of the input grid contains at least one frog.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052 \cdot 10^5.

Output

For each test case, output a single line containing the minimum kk such that there exists a valid jumping scheme.

Note

In the first test case, two frogs can jump to each other's cells.

In the second test case, the left frog can jump down, and the right frog can jump up. After the jumps, the total number of frogs in each row and each column remains 11.

of
fo

In the third test case, three frogs can all jump to the same cell (1,2)(1,2), although it is not a valid answer, since the number of frogs in the first column changes from 11 to 00.

of f fo
ooo
Sample 1
Input
4
2
ff
oo
2
fo
of
3
fof
ofo
1
f
o
Output
0
0
1
1

Discussions & Comments

Share your approach or ask questions about this problem (0)

You must be logged in to comment or start a discussion on this problem.

Log In

No comments yet. Be the first to comment!

Actions

Open on Codeforces

About Platform

CO
Codeforces
External Judge

Problem Discussions

0

Have questions or want to share your solution approach? Join the discussion.

View / write comments