# Practice on Toph

Participate in exhilarating programming contests, solve unique algorithm and data structure challenges and be a part of an awesome community.

# A Game of Bots

By ramisa.alam · Limits 1s, 512 MB

You were idly scrolling through your Phesbook feed one morning when you discovered an ongoing event called “A Game of Bots”. It turns out to be an AI contest where participants have to build their own AI agents and win against opponents’ agents in matches of chess.

You can see the tournament has already begun and $N$players have started playing the games. These players have already played against each other. So a total of $N * (N - 1) / 2$ rounds have completed. If you enter the tournament now, you’ll have to play against each of these $N$players. So you want to have an idea about their strength.

From your experiences, you know that in these games a stronger bot always wins against a weaker bot. If both the participating bots in a game have similar strengths, the game is tied.

You can easily find out the results of the previous matches from the event page. Can you determine the relative strength of the participating players from these results?

Here, the relative strength of each of the $N$players is a number from $[1, N]$ with a larger value indicating a stronger player.

It is guaranteed that at least one valid assignment of relative strengths for the players exists.

## Input

The first line of input contains a single integer $t ( 1 \le t \le 100 )$ — the number of test cases. Description of the test cases follows.

The first line of each test case contains an integer $N ( 1 \le N \le 1000)$— the number of bots currently participating in the tournament.

Each of the next $N * ( N - 1 ) / 2$ lines contain the description of a match.

Each match is described by 3 integers: $x_i, y_i, w_i ( 1 \le x_i , y_i \le N , 0 \le w_i \le N)$ where $x_i$and $y_i$ are the ids of the players participating in the $i^{th}$ game and $w_i$ is the id of the winning player. In case of ties, $w_i = 0$.

Each player appears in exactly $N-1$ matches against $N-1$ different opponents.

The sum of $N$ over all test cases does not exceed $1000$.

## Output

For each test case, print one line containing an array $S$ containing $N$ space-separated integers.

The $i^{th}$ element of the array - $S_i ( 1 \le S_i \le N)$ is the relative strength of the $i^{th}$ player. A larger value of $S_i$ indicates a stronger player.

If there are multiple such arrays, print the one in which the maximum strength among the $N$ players is minimized.

## Sample

InputOutput
2
3
1 2 2
1 3 3
2 3 3
4
1 2 2
3 4 3
1 3 3
2 3 3
1 4 0
2 4 2


1 2 3
1 2 3 1


In the second test case, player 1 has strength 1, and player 2 has strength 2. So player 2 wins the first match.

The 5th match ties since player 1 and player 4 have the same strength

### Statistics

77% Solution Ratio

bisnu_sarkarEarliest, 2M ago

bisnu_sarkarFastest, 0.0s

bisnu_sarkarLightest, 131 kB

Shahriar.699347Shortest, 742B