RPS string
시간 제한2초메모리 제한512 MB
줄지어 선 로봇들 사이에서 심판이 가위바위보 대결 순서를 정해 특정 로봇만 살아남게 만들 수 있는지 각 로봇마다 판정한다.
문제
The robots battle in rock-paper-scissors takes place in Innopolis. All advanced robots are engaged in full-fledged work, so the simplest bots participate in the battles. Each of them always play the same shape: a rock, or scissors, or a paper.

The robots stand in a line. Then the judge can choose two neighboring robots, and make them play one round of rock-paper-scissors. If one of them beats the other, the loser is eliminated from the game and is removed from the sequence of robots, the sequence of the remaining ones doesn't change. There are two versions of the rules. In the first of them, if the robots played the same shape, the judge can independently choose which one to remove from the game. In the second version, if the robots played the same shape, both robots remain. The robot wins if all other robots are eliminated from the game.
However, the judge has become very bored with the competition, so he wants to find out for each robot whether the judge can choose pairs in each round so that this robot wins. Help him!
입력
You will need to solve several testcases.
The first line contains an integer () --- the number of tests in the input.
Next, tests are given, each consisting of an integer and a string.
The integer denotes the version of the rules that is used in the current robot layout .
Then the string follows, it contains () lowercase English letters 'r', 'p' and 's', describing the list of robots. More precisely, the characters 'r', 'p' and 's' denote robots that play rock, paper, and scissors, respectively.
The total sum of for given tests does not exceed .
출력
Output lines: one for each test.
The line should contain digits '0' and '1', for each from 1 to print '1' if the judge can choose such pairs for each round that the -th robot wins, and '0' otherwise.
힌트
First test example: "rpspp", . Let's identify the robots with integers from 1 to 5 from left to right.
-
In order for the robot 1 to win, the judge can act as follows:
- The judge chooses robots 4 and 5, they play the same shape, so the judge decides that the 5th robot is eliminated. Robots {1, 2, 3, 4} remain.
- The judge chooses robots 2 and 3, the 2nd one is eliminated. Robots {1, 3, 4} remain.
- The judge chooses robots 3 and 4, the 4th one is eliminated. Robots {1, 3} remain.
- The judge chooses robots 1 and 3, the 3rd one is eliminated. The robot 1 wins.
-
For the robot 2, the judge can't get rid of the 1st robot without removing the 2nd, so the 2nd can't win.
-
In order for the robot 3 to win, the judge can act as follows:
- The judge chooses robots 4 and 5, they play the same shape, so the judge decides that the 5th robot is eliminated. Robots {1, 2, 3, 4} remain.
- The judge chooses robots 1 and 2, the 1st one is eliminated. Robots {2, 3, 4} remain.
- The judge chooses robots 2 and 3, the 2nd one is eliminated. Robots {3, 4} remain.
- The judge chooses robots 3 and 4, the 4th one is eliminated. The robot 3 wins.
-
In order for the robot 4 to win, the judge can act as follows:
- The judge chooses robots 4 and 5, they show the same shape, so the judge decides that the 5th robot is eliminated. Robots {1, 2, 3, 4} remain.
- The judge chooses robots 2 and 3, the 2nd one is eliminated. Robots {1, 3, 4} remain.
- The judge chooses robots 1 and 3, the 3rd one is eliminated. Robots {1, 4} remain.
- The judge chooses robots 1 and 4, the 1st one is eliminated. The robot 4 wins.
-
In order for the robot 5 to win, the judge can act as follows:
- The judge chooses robots 4 and 5, they show the same shape, so the judge decides that the 4th robot is eliminated. Robots {1, 2, 3, 5} remain.
- The judge chooses the robots 2 and 3, the 2nd one is eliminated. Robots {1, 3, 5} remain.
- The judge chooses robots 1 and 3, the 3rd one is eliminated. Robots {1, 5} remain.
- The judge selects robots 1 and 5, the 1st one is eliminated. The robot 5 wins.
Second test example: "pps", . Let's identify the robots with integers from 1 to 3 from left to right.
-
For the robot 1 the judge can't get rid of the 2nd robot without removing the 1st, so the 1st can't win.
-
For the robot 2, the judge can't get rid of the 1st robot without removing the 2nd, so the 2nd can't win.
-
In order for the robot 3 to win, the judge can act as follows:
- The judge selects robots 2 and 3, the 2nd one is eliminated. Robots {1, 3} remain.
- The judge selects robots 1 and 3, the 1st one is eliminated. The robot 3 wins.