CF2064A.Brogramming Contest

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Brogramming Contest

One day after waking up, your friend challenged you to a brogramming contest. In a brogramming contest, you are given a binary string^{\text{∗}} ss of length nn and an initially empty binary string tt. During a brogramming contest, you can make either of the following moves any number of times:

  • remove some suffix^{\text{†}} from ss and place it at the end of tt, or
  • remove some suffix from tt and place it at the end of ss.

To win the brogramming contest, you must make the minimum number of moves required to make ss contain only the character 0 and tt contain only the character 1. Find the minimum number of moves required.

^{\text{∗}}A binary string is a string consisting of characters 0 and 1.

^{\text{†}}A string aa is a suffix of a string bb if aa can be obtained from deletion of several (possibly, zero or all) elements from the beginning of bb.

Input

The first line contains an integer tt (1t1001 \le t \le 100) — the number of test cases.

The first line of each test case is an integer nn (1n10001 \le n \le 1000) — the length of the string ss.

The second line of each test case contains the binary string ss.

The sum of nn across all test cases does not exceed 10001000.

Output

For each testcase, output the minimum number of moves required.

Note

An optimal solution to the first test case is as follows:

  • s=00110s = \texttt{00}\color{red}{\texttt{110}}, t=t = empty string.
  • s=00s = \texttt{00}, t=110t = \texttt{11}\color{red}{\texttt{0}}.
  • s=000s = \texttt{000}, t=11t = \texttt{11}.

It can be proven that there is no solution using less than 22 moves.

In the second test case, you have to move the whole string from ss to tt in one move.

In the fourth test case, you don't have to do any moves.

Samples

5
5
00110
4
1111
3
001
5
00000
3
101
2
1
1
0
3

在线编程 IDE

建议全屏模式获得最佳体验