We need to understand the problem: Given N locations 0..N-1, each has an exit leading either to another location (0 <= A[i] <= N-1) or to a win (A[i] == -1). The player starts at entrance of location 0. Then presumably the player goes through the location and then exits. The exit leads to entrance of another location (or wins). So it's essentially a directed graph where each node i has out-degree 1 (except maybe -1 has no outgoing, but we treat as a terminal winning state). Starting from node 0, follow the edges. If we ever reach a node with A[i] == -1, we win. If we get stuck in a cycle that never leads to -1, we lose (since we will loop forever). So it's basically: Starting from node 0, perform a traversal following the directed edges. If we reach a node with value -1, win; else if we encounter a cycle before hitting -1, lose.
But note: The graph may have nodes that lead to -1 indirectly. Also, there might be multiple edges, but each node has exactly one outgoing. So we just need to simulate walking from 0 until we either encounter -1 or detect a cycle. However, N can be large? The problem doesn't specify constraints. But typical problems like this: N up to 10^5 or 10^6. So we need efficient cycle detection.
We can do a visited array: states: 0 = unvisited, 1 = visiting (in current path), 2 = processed (visited and determined outcome). Or we can use a DFS with cycle detection. Since it's a functional graph (each node has exactly one outgoing edge, possibly to -1 as a sentinel), we can simply simulate and keep an array visited, marking steps along the path. If we encounter a node that has been visited in the current path (i.e., we are revisiting before completing), it's a cycle and we lose (unless we encountered -1 earlier). But careful: if the cycle includes a node that eventually leads to -1? That's impossible because if a node leads to -1, then following its outgoing we would exit, so it's not a cycle. Actually, if a node leads to -1, its outgoing is -1 (win). So that node's outgoing is not a node; it's a terminal. So cycles are only formed by nodes that point to each other, none pointing to -1. So if we encounter a cycle, we will never win.
Thus algorithm: start at node 0. While True: if node == -1? Actually A[node] may be -1. But note: The player reaches the exit from location i; if A[i] == -1, they win. So if we are at location i, we check A[i]. If A[i] == -1, we win. Else we go to A[i] as the next location. So we need to follow from node index. Implementation: current = 0; while True: if visited[current] == True: then we are in a cycle (revisiting). Since we have visited before, but did we already determine outcome? Actually if we visited before but haven't yet determined outcome? In simple simulation, we can keep a set of visited nodes. At each step, if A[current] == -1: print Win; break. Else if current in visited: print Lose; break. Else add current to visited and set current = A[current].
But careful: What if the graph has a cycle that does not include node 0, but we might first go to some nodes and then later reach a node that leads into a cycle? Then we will eventually loop. So detection of cycle works.
But is there any scenario where we might encounter a node that was visited but that node leads to -1 indirectly? Actually if a node leads to -1, then its outgoing is -1, so you cannot revisit it because after you go to -1 you would have terminated. So if a node leads to -1, you never come back to any node after it because it's terminal. So that's safe.
Thus simple simulation with visited set works.
Edge Cases: N could be 0? Not possible; at least 1? Probably N >=1.
We also need to process multiple test cases. Input format: first line T (number of test cases). For each test case, first line N (number of elements). Second line the array A of N integers.
Output: For each test case, print "Win" or "Lose" on its own line.
Sample matches.
Complexities: O(N) per test case.
But what about large N? visited array of booleans size N fine.
Potential pitfalls: If the path is long (like N up to 10^5) but simulation works.
We must be careful: visited array reset per test case.
Alternative: Use two-pointer cycle detection (Floyd) but simpler to use visited.
But careful: In functional graph, there could be multiple branches merging, but since each node has exactly one outgoing, it's a collection of cycles with trees feeding into them. Starting from node 0, we will either eventually hit a cycle or reach -1. So we can detect cycle by marking visited nodes as we go. However, note that if we revisit a node that was visited in a previous path but not part of current path? In a functional graph, starting from a single node, the path is a single chain that either ends at -1 or enters a cycle. Since each node has exactly one outgoing, the path from node 0 is uniquely determined. There's no branching, so we only follow one path. So we will never encounter a node that was visited but not part of the current path? Actually, if the graph contains merges, it is possible that node 0's path leads to some node X that has been visited earlier? But how could we have visited X earlier if we only start at node 0 and follow forward? Because there is only one path from 0. The only way to revisit a node is if we have already been there, which means we are cycling. There is no possibility of encountering a node visited earlier that is not part of the current path because we only go forward; if we had visited X before and then later come to X again, that means there is a cycle (since the path from 0 to X includes X earlier). However, if there were multiple starting points, but we only start from 0, it's a single path. So indeed visited detection is fine.
Thus solution is straightforward.
Let's consider testcases:
Input:
3
2
1 -1
3
1 0 -1
3
0 1 2
Case1: N=2, A=[1,-1]. start at 0: A[0]=1 => go to 1, visited={0}. At 1: A[1]=-1 => Win.
Case2: N=3, A=[1,0,-1]. start 0: A[0]=1 => go to 1, visited={0}. At 1: A[1]=0 => go to 0, but 0 visited => Lose.
Case3: N=3, A=[0,1,2]. start 0: A[0]=0 => go to 0, visited already? Actually we start at 0, check A[0]=0, which is not -1. Before moving, we should mark visited? Typically: We check if A[current]==-1, else if current in visited, lose; else add current to visited and move. So at current=0, visited empty. Check A[0] != -1, current not in visited? Not yet, so add 0 to visited, then set current = A[0] = 0. Now current=0 is in visited, so Lose. So output Lose.
Works.
One nuance: The problem statement says: "Rose started the game by entering location 0." So the first location entered is location 0. Then the exit from that location leads to something. So the process as described: Enter location, then exit. So we start at location 0. So we need to check the exit of location 0. So algorithm consistent.
Potential pitfalls: If N=1 and A[0] = -1: Win. If A[0] = 0: Lose. Works.
If A[0] = something else, but only one node: if A[0] is 0 (valid) then cycle. If A[0] is something else out of range? But problem says A[i] is either -1 or between 0 and N-1. So okay.
Implementation details: read integer T. For each test case: read N (maybe N line could be empty? but we'll read using input().split). Then read the next line containing N integers. Use a list A of ints. Then simulate.
We'll use a boolean list visited = [False]*N. But careful: If N large, we allocate each test case. That's okay.
But note: If we ever get to a node that is already visited, we lose. However, we need to consider: what if we are at a node that is visited but we haven't checked its A[i] for -1? Actually we should first check A[current]==-1; if so, win immediately. Only then check for cycle. But if A[current]==-1, we win regardless of visited status (since we would have exited). So order: check if A[current] == -1: print Win; break. Else if visited[current]: print Lose; break. Else mark visited[current]=True; set current = A[current].
Edge: Starting node could be visited? Initially visited[0] is False. So ok.
Another scenario: If we have visited a node but later we reach it again after some steps. That's cycle.
Thus algorithm correct.
But what about extremely long path that might exceed recursion depth? We use iterative loop.
Time complexity: O(N) per test case. Space: O(N) for visited.
Potential memory optimization: We could use an integer array to mark visited steps (like assign a step counter). But boolean array is fine.
We need to output exactly "Win" or "Lose" per test case.
Check sample output: "Win", "Lose", "Lose". Good.
Now I'll produce Python code.
But there might be some hidden nuance: The problem says "Rose loves to play games. This problem is about a game he recently played." Possibly a known problem: "Game of exit" etc. But simple.
But double-check: Could there be a scenario where we have a node that leads to -1 but we also have a cycle that doesn't include -1? Starting from 0, if we encounter a cycle before hitting -1, we lose. So if the path from 0 goes through nodes and eventually reaches a node that has A[node] = -1, we win. So straightforward.
One more nuance: What if the initial node 0 itself has A[0] = -1? Then we win immediately without moving? According to process: start by entering location 0. Then we take the exit. If A[0] == -1, then upon reaching the exit from location 0, they win. So win. Our algorithm: start current = 0; check A[current] == -1 -> True, so win. Good.
Now implement.
We'll read T from input, for each test case, read N, read array. Might have multiple lines for array if N large? But we assume one line. Use map(int, sys.stdin.read().split()) for speed if needed. But simple input reading is fine.
Let's write:
import sys
def solve():
data = sys.stdin.read().split()
if not data: return
it = iter(data)
T = int(next(it))
out_lines = []
for _ in range(T):
N = int(next(it))
A = [int(next(it)) for _ in range(N)]
visited = [False]*N
current = 0
result = None
while True:
if A[current] == -1:
result = "Win"
break
if visited[current]:
result = "Lose"
break
visited[current] = True
current = A[current]
out_lines.append(result)
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()
But wait: There's a potential bug: The visited array is of size N, but what if we ever encounter a node that is out of range? No, A[current] is either -1 or between 0 and N-1. So current always in [0, N-1] after assignment because we only assign from A[current] if not -1. So visited indices valid.
Edge: If N=0? Not possible.
One more: Could there be a scenario where we encounter a node with A[current] == -1 but visited[current] is True? That doesn't matter because we win before checking visited.
Alright.
But we should also consider memory usage: visited as boolean list of size N, each test case. For multiple test cases, may be large but okay.
Now, is there any possibility of infinite loop? The while loop will always terminate because either we win, lose, or the path length is bounded by N (if we don't encounter -1, we must eventually revisit a node because there are only N nodes). So we will terminate in at most N+1 steps.
Thus solution seems correct.
But hold on: The problem description: "Rose loves to play games... Print 'Win' if he can win the game." Possibly there is an interpretation about ability to choose something? But reading, it says: "You are given an array aka A with N elements. For each i, A[i] describes the exit from location i. If A[i] is a number between 0 and N-1, inclusive, it means that the exit from location i leads to the entrance of location A[i]. Otherwise, A[i] will be -1 and it means that if the player reaches this exit, they win the game." So it's deterministic; no choices. So it's simply following the path.
Thus answer is as above.
But we should check sample: For test case 2, our algorithm gives Lose as expected.
Potential additional test: N=4, A=[1,2,3,-1] -> start 0->1->2->3->-1 Win.
N=4, A=[1,2,0,-1] -> start 0->1->2->0 cycle, Lose because never reaches -1.
If there is a path that goes into a cycle after passing a -1? Not possible because -1 is terminal.
Thus answer.
Now, I'll produce final solution with explanation.
But wait: The problem statement: "Rose started the game by entering location 0." It might be that he enters location 0, then from there he goes to the exit, which leads to something. So we consider the initial location 0 as the starting point, and we check its exit. That's what we did.
Now let's ensure we are reading input correctly. Input format: "First line contains the no. of testcases and each testcase consist of 2 lines first containing the no. of elements in array and next line containing those elements." So we read T, then for each test case, read N, then read N integers possibly across lines? But they say next line containing those elements. So likely one line. But sometimes for large N, they might wrap across lines. We'll use reading all ints from input as tokens to be safe. Already using split.
Now implement.
One more nuance: If N is huge (like 10^6) and many test cases, we might want to avoid recursion and use fast I/O. We'll use sys.stdin.read and sys.stdout.write.
Now produce final answer.
But the problem may be from some contest: "Rose and Game" but it's fine.
Thus final solution.
Will we need to handle the case where starting node 0 is -1? Actually A[0] may be -1. That's covered.
Now produce final response with explanation.
In the explanation, I'll describe that it's a functional graph and we detect cycle or -1.
Potential pitfalls: The solution above might produce a runtime error if N=0? But not.
Now writing final.
Note: In the code we used visited list of booleans. However, if N is up to maybe 2e5 per test, it's fine.
But we can also use a set to track visited, but list is more efficient.
One more improvement: We could use a sentinel for visited: we could mark visited by setting A[current] to a special value, but that would modify array, which we could if allowed? But not necessary.
Thus answer is fine.
Now I'll generate final output.
```python
import sys
def solve() -> None:
data = sys.stdin.read().split()
if not data:
return
it = iter(data)
t = int(next(it))
out = []
for _ in range(t):
n = int(next(it))
a = [int(next(it)) for _ in range(n)]
visited = [False] * n
cur = 0
result = None
while result is None:
if a[cur] == -1:
result = "Win"
elif visited[cur]:
result = "Lose"
else:
visited[cur] = True
cur = a[cur]
out.append(result)
sys.stdout.write("\n".join(out))
if name == "main":
solve()