#P1732B. Ugu
Ugu
Description
A binary string is a string consisting only of the characters 0 and 1. You are given a binary string . It is necessary to make this string non-decreasing in the least number of operations. In other words, each character should be not less than the previous. In one operation, you can do the following:
- Select an arbitrary index in the string;
- For all , change the value in the -th position to the opposite, that is, if , then make , and vice versa.
What is the minimum number of operations needed to make the string non-decreasing?
Each test consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of test cases follows.
The first line of each test cases a single integer () — the length of the string.
The second line of each test case contains a binary string of length .
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, output a single integer — the minimum number of operations that are needed to make the string non-decreasing.
Input
Each test consists of multiple test cases. The first line contains an integer () — the number of test cases. The description of test cases follows.
The first line of each test cases a single integer () — the length of the string.
The second line of each test case contains a binary string of length .
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, output a single integer — the minimum number of operations that are needed to make the string non-decreasing.
Note
In the first test case, the string is already non-decreasing.
In the second test case, you can select and then .
In the third test case, you can select and get , and then select . As a result, we get , that is, a non-decreasing string.
In the sixth test case, you can select at the first iteration and get . Then choose , then . Then we select , getting the non-decreasing string .