#P9881. 0 vs 1
0 vs 1
0 vs 1
Problem Description
Two players named Zero and One are playing a strategic game with a string of characters consisting of only s and s. The rules of the game are as follows: The players take turns removing a single character from either the left or the right end of the string, starting with the player named Zero. If Zero picks a , he lose the game. Similarly, if One picks a , he loses the game. If all characters in the string are removed and no one has lost, the game ends in a draw. If both players are playing optimally, your task is to determine who will win the game, or whether the game will end in a draw.
Input
The first line contains a single integer (), denoting the number of test cases. The first line of each test case consists of an integer (), denoting the length of the string. The second line contains a string of length consisting of only s and s, denoting the initial string of the game. It is guaranteed that there are no more than test cases with .
Output
For each test case, output a integer in a single line. If One will win the game, output . If Zero will win the game, output . If the game will end in a draw, output .
Sample Input
2
3
110
5
01010
Sample Output
1
-1
Hint
In the first test case, Zero can only pick up the character 0 from the right in his first turn. Then, it is One's turn to pick up a character. When it comes back to Zero's turn, he can only pick up the character 1, so Zero loses.
Source
2023“钉耙编程”中国大学生算法设计超级联赛(8)