#P1943F. Minimum Hamming Distance

Minimum Hamming Distance

No submission language available for this problem.

Description

You are given a binary string^\dagger ss of length nn.

A binary string pp of the same length nn is called good if for every ii (1in1 \leq i \leq n), there exist indices ll and rr such that:

  • 1lirn1 \leq l \leq i \leq r \leq n
  • sis_i is a mode^\ddagger of the string plpl+1prp_lp_{l+1}\ldots p_r

You are given another binary string tt of length nn. Find the minimum Hamming distance§^\S between tt and any good string gg.

^\dagger A binary string is a string that only consists of characters 0\mathtt{0} and 1\mathtt{1}.

^\ddagger Character cc is a mode of string pp of length mm if the number of occurrences of cc in pp is at least m2\lceil \frac{m}{2} \rceil. For example, 0\mathtt{0} is a mode of 010\mathtt{010}, 1\mathtt{1} is not a mode of 010\mathtt{010}, and both 0\mathtt{0} and 1\mathtt{1} are modes of 011010\mathtt{011010}.

§^\S The Hamming distance of strings aa and bb of length mm is the number of indices ii such that 1im1 \leq i \leq m and aibia_i \neq b_i.

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

The first line of each test case contains a single integer nn (1n1041 \le n \le 10^4) — the length of the binary string ss.

The second line of each test case contains a binary string ss of length nn consisting of characters 0 and 1.

The third line of each test case contains a binary string tt of length nn consisting of characters 0 and 1.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6, with the additional assurance that the sum of n2n^2 over all test cases does not exceed 10810^8

For each test case, print the minimum Hamming distance between tt and any good string gg.

Input

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

The first line of each test case contains a single integer nn (1n1041 \le n \le 10^4) — the length of the binary string ss.

The second line of each test case contains a binary string ss of length nn consisting of characters 0 and 1.

The third line of each test case contains a binary string tt of length nn consisting of characters 0 and 1.

It is guaranteed that the sum of nn over all test cases does not exceed 10610^6, with the additional assurance that the sum of n2n^2 over all test cases does not exceed 10810^8

Output

For each test case, print the minimum Hamming distance between tt and any good string gg.

Sample Input 1

3
3
000
000
4
0000
1111
6
111111
000100

Sample Output 1

0
2
1

Note

In the first test case, g=000g=\mathtt{000} is a good string which has Hamming distance 00 from tt.

In the second test case, g=0011g=\mathtt{0011} is a good string which has Hamming distance 22 from tt. It can be proven that there are no good strings with Hamming distance less than 22 from tt.

In the third test case, g=001100g=\mathtt{001100} is a good string which has Hamming distance 11 from tt.