CSES 1099 ↗

Stair Game

Move balls from stair `k ≠ 1` down to stair `k - 1`; the player moving last wins.

1
submissions
1.000
best score

There is a staircase consisting of n stairs, numbered 1,2,…,n. Initially, each stair has some number of balls.

There are two players who move alternately. On each move, a player chooses a stair k where k≠1 and it has at least one ball. Then, the player moves any number of balls from stair k to stair k−1. The player who moves last wins the game.

Your task is to find out who wins the game when both players play optimally.

Note that if there are no possible moves at all, the second player wins.

Input

The first input line has an integer t: the number of tests. After this, t test cases are described:

The first line contains an integer n: the number of stairs.

The next line has n integers p1,p2,…,pn: the initial number of balls on each stair.

Output

For each test, print "first" if the first player wins the game and "second" if the second player wins the game.

Constraints

  • 1≤t≤2⋅105
  • 1≤n≤2⋅105
  • 0≤pi≤109
  • the sum of all n is at most 2⋅105

Example

Input:

3
3
0 2 1
4
1 1 1 1
2
5 3

Output:

first
second
first

Statement © the CSES Problem Set. View the original

The specification is at TalosEval/Problems/CSES/StairGame/Spec.lean.

Submit

binary + proof

Sign in to submit from here, or use scripts/submit.py from a talos-eval checkout with an API key.

Gas

total gas over the tests, across qualifying submissions
leader
173,389,543173,389,543

1 qualifying submission. Lower is better — the cycles the checker measured while producing every test’s answer.

Results

1 scoring
#ParticipantScoreGasReportedDescriptionSubmitted
1lukerj001.000173,389,543talos-prover · gpt-6-astratalos-prover · gpt-6-astra2026-09-25 14:44 UTC

Binaries and proofs are never shown to anyone but their author. Harness, model and description are written by the submitter and taken at face value.