#P1678B2. Tokitsukaze and Good 01-String (hard version)
Tokitsukaze and Good 01-String (hard version)
No submission language available for this problem.
Description
This is the hard version of the problem. The only difference between the two versions is that the harder version asks additionally for a minimum number of subsegments.
Tokitsukaze has a binary string of length , consisting only of zeros and ones, is even.
Now Tokitsukaze divides into the minimum number of contiguous subsegments, and for each subsegment, all bits in each subsegment are the same. After that, is considered good if the lengths of all subsegments are even.
For example, if is "11001111", it will be divided into "11", "00" and "1111". Their lengths are , , respectively, which are all even numbers, so "11001111" is good. Another example, if is "1110011000", it will be divided into "111", "00", "11" and "000", and their lengths are , , , . Obviously, "1110011000" is not good.
Tokitsukaze wants to make good by changing the values of some positions in . Specifically, she can perform the operation any number of times: change the value of to '0' or '1' (). Can you tell her the minimum number of operations to make good? Meanwhile, she also wants to know the minimum number of subsegments that can be divided into among all solutions with the minimum number of operations.
The first contains a single positive integer () — the number of test cases.
For each test case, the first line contains a single integer () — the length of , it is guaranteed that is even.
The second line contains a binary string of length , consisting only of zeros and ones.
It is guaranteed that the sum of over all test cases does not exceed .
For each test case, print a single line with two integers — the minimum number of operations to make good, and the minimum number of subsegments that can be divided into among all solutions with the minimum number of operations.
Input
The first contains a single positive integer () — the number of test cases.
For each test case, the first line contains a single integer () — the length of , it is guaranteed that is even.
The second line contains a binary string of length , consisting only of zeros and ones.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print a single line with two integers — the minimum number of operations to make good, and the minimum number of subsegments that can be divided into among all solutions with the minimum number of operations.
Samples
Note
In the first test case, one of the ways to make good is the following.
Change , and to '0', after that becomes "1100000000", it can be divided into "11" and "00000000", which lengths are and respectively, the number of subsegments of it is . There are other ways to operate times to make good, such as "1111110000", "1100001100", "1111001100", the number of subsegments of them are , , respectively. It's easy to find that the minimum number of subsegments among all solutions with the minimum number of operations is .
In the second, third and fourth test cases, is good initially, so no operation is required.