#P1437B. Reverse Binary Strings
Reverse Binary Strings
No submission language available for this problem.
Description
You are given a string of even length . String is binary, in other words, consists only of 0's and 1's.
String has exactly zeroes and ones ( is even).
In one operation you can reverse any substring of . A substring of a string is a contiguous subsequence of that string.
What is the minimum number of operations you need to make string alternating? A string is alternating if for all . There are two types of alternating strings in general: 01010101... or 10101010...
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer (; is even) — the length of string .
The second line of each test case contains a binary string of length ( {0, 1}). String has exactly zeroes and ones.
It's guaranteed that the total sum of over test cases doesn't exceed .
For each test case, print the minimum number of operations to make alternating.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains a single integer (; is even) — the length of string .
The second line of each test case contains a binary string of length ( {0, 1}). String has exactly zeroes and ones.
It's guaranteed that the total sum of over test cases doesn't exceed .
Output
For each test case, print the minimum number of operations to make alternating.
Samples
Note
In the first test case, string 10 is already alternating.
In the second test case, we can, for example, reverse the last two elements of and get: 0110 0101.
In the third test case, we can, for example, make the following two operations:
- 11101000 10101100;
- 10101100 10101010.