#P7387. 「EZEC-6」象棋

「EZEC-6」象棋

Description

Chinese chess is played by two players, where Red moves first and Black moves second. There are many kinds of pieces in Chinese chess. PF especially likes the "cannon". The cannon move is:

If, for a cannon of one side and a cannon of the opponent, there is exactly one cannon between their positions, then this side may move the opponent's cannon off the board, and move their own cannon to the opponent cannon's position.

PF is tired of the traditional way of playing Chinese chess, so he takes out a board with 11 row and nn columns. Each position on the board has exactly one cannon, and each cannon belongs to Red or Black. In each turn, the player to move may perform one move, or choose not to move, and then pass the turn to the opponent. If both sides agree to end, or there is no move available, the game ends.

There will be TT games. In each game, PF is always Red. Define the winning condition as: one side has more remaining cannons than the other side. He wants to know whether, if both sides use optimal strategies, he has a forced win strategy.

Input Format

The first line contains an integer TT, representing the number of testdata.

For each test case, the first line contains an integer nn, representing the board size.

The next line contains a string, where the ii-th integer aia_i represents the type of the ii-th piece: 11 means a Red cannon, and 00 means a Black cannon.

Output Format

Output TT lines in total. If the ii-th test case has a forced win strategy, output WIN. If it is a draw, output TIE. Otherwise, output LOSE.

4
3
101
5
01100
5
01110
4
1000
WIN
TIE
WIN
LOSE

Hint

Since the input size is large, please use a faster input method.

Constraints

This problem uses bundled tests.

Subtask ID TT\le nn\le n\sum n\le Score
11 2020 33 6060 55
22 10310^3 66 6×1036\times10^3 1010
33 10510^5 1515 1.5×1061.5\times10^6 1515
44 200200 500500 2020
55 10510^5 10610^6 2×1062\times10^6 2525
66 10710^7 2×1072\times10^7

For 100%100\% of the data: 1T1051\le T \le 10^5, 1n1071 \le n \le 10^7, n2×107\sum n \le 2\times 10^7, a{0,1}a \in \{0,1\}.

Sample Explanation

For the first test case, no piece can move, and the number of Red pieces is greater than the number of Black pieces, so the first player has a forced win strategy.

For the second test case, one possible draw line is:

0 1 1* 0 0*
0 1 0 1

For the third test case, there are two possible outcomes under optimal play for both sides:

0 1 1* 1 0*
0* 1 1* 1
1 0 1
0* 1 1* 1 0
1 1* 1 0*
1 0 1

In both results, the number of remaining Red cannons is greater, so Red wins.

For the fourth test case, Red has only one feasible move:

1* 0 0* 0
0 1 0

After no moves remain, Black has more cannons.

Translated by ChatGPT 5