(1, 2) Nim

Sprague and Grundy are playing a game. There are N piles of stones numbered 1, 2, ..., N. The i-th pile contains A[i] stones.

The following is defined as a move:

  • Choose a non-empty pile, and remove any non-zero number of stones from it. Formally, choose some i with A[i] > 0 and choose 1 ≤ j ≤ A[i]. Then replace A[i] by A[i] - j.

The players take alternating turns starting with Sprague. In his turn, Sprague must make exactly one move. The rule for Grundy's turn is the following:

  • First Grundy must make one move.
  • After this move, if atleast one stone is remaining, he must make exactly one more move.

The player to remove the last remaining stone wins the game. Find out who wins if both play optimally.

Input Format

  • The first line contains T, the number of testcases. Then the testcases follow, each consisting of two lines:
    • The first line of each testcase contains N.
    • The second line contains N space separated integers A[1], A[2], ..., A[N].

Constraints

  • 1 ≤ T ≤ 10^4
  • 1 ≤ N ≤ 10^5
  • 1 ≤ A[i] ≤ 10^9 for all 1 ≤ i ≤ N
  • The sum of N over all testcases doesn't exceed 10^5

Output Format

For each testcase, print a single line containing Sprague if Sprague wins the game and Grundy otherwise. Please note that the checker is case-sensitive. Printing sprague or sPRAGuE instead of Sprague will give Wrong Answer.

Sample 0

Input

3
2
1 2
1
5
4
1 7 2 9

Output

Grundy
Sprague
Grundy

Explanation

In the first testcase, one can verify that Grundy wins. For example, if Sprague removes 1 stone from the second pile, then in his turn, Grundy can remove 1 stone from the first pile in his first move and 1 stone from the second pile in his second move. If Sprague removes 2 stones from the second pile, Grundy can remove the only remaining stone in one move and win the game instantly.

Time Limit
2000 ms
Memory Limit
262144 KiB
Please login to submit.
Ln: 1, Col: 1
Key Map: default
Login to submit.
Time: 30 Aug 2025, Sat 20:49:01
© 2025 UNIQUE BIT TECHNOLOGIES PVT. LTD. All Rights Reserved.