Input Format: T T N N
Input Format: T T N N
You’re given a row of seats. Each seat is either occupied by a woman (denoted by xx) or a man (denoted by xy).
The objective is to find the minimum number of seat exchanges required such that the men and women are seated
alternately.
Input Format
The first line of input consists of an integer t denoting the number of test cases. t test cases follow. Each test
case consists of two lines. The first line of each test case consists of an integer n denoting the number of seats.
Second line consists of n space separated tokens, each token denoting the occupant of that particular seat.
Output Format
For each test case, print the number of seat exchanges required. If an alternate seating is impossible, print -1 .
Sample Input
5
3
xx xx xx
2
xx xy
4
xx xx xy xy
8
xx xx xy xy xy xx xx xy
7
xx xy xx xy xx xy xy
Sample Output
-1
0
1
2
3
Constraints
1 <= t <= 1000
1 <= n <= 10000
Explanation
For xx xx xy xy , one can exchange seat 1 with seat 4 giving xy xx xy xx giving an alternate seating
arrangement.