Singularity of the Nim
Time limit2sMemory limit1024 MB
Given a staircase game where taking x coins from a step adds x^j coins to each lower step j, decide whether the first or second player wins.
- Level
Hard8 of 10
- Topics
- Game theory, Math, Implementation
- Solved
- No attempts yet
Problem
Exponential staircase nim is a game for two players on a staircase of steps, with a huge number of coins. The players take turns. At the start, each step has some coins on it.
Let be the number of coins on the -th step from the bottom. The figure below shows an example with and .

On each turn, a player picks a step that has coins and takes between 1 and coins from it.
If a player takes coins from the -th step from the bottom, new coins are added to every step below it, with the amount growing exponentially in . Precisely, coins are added to the -th step from the bottom for each .
The figures below show the result of choosing , from the initial example, and the result of choosing , .

If a player takes many coins from a high step, the game grows faster than anyone can follow. You will see a singularity when that happens.
The game goes on until someone has no coins left to take. That player loses.
Assume both players play to win. Determine whether the first or the second player wins.
Input
The first line contains the number of test cases . Then each test case follows on two lines, for a total of lines.
The first line of each test case contains the number of steps and the maximum number of coins that can be taken in one turn.
The second line contains integers , the number of coins on each step at the start of the game.
Output
For each test case, print one line. Print First if the first player wins, and Second if the second player wins.
Constraints
- The sum of all values is at most .