Inheritance (Translated)

JOI Spring Training Camp 2014/15
Original Statement / Submission Site

Problem Statement

Mr. JOI, a tycoon who owned all the railways in the country of IOI, has passed away. According to his will, the railways will be inherited and divided among his children.

There are N cities and M railways connecting them in IOI. Railway i connects cities Ai and Bi bidirectionally and generates an annual income of Ci yen. The income values C1, ..., CM are all distinct. Multiple railways may connect the same pair of cities.

His will specifies the inheritance as follows:

Each child, being greedy like their father, chooses their share to maximize the total annual income. We guarantee that the optimal selection (maximum total income without forming cycles) is unique for each child.

Task

Given the railway information and number of children, write a program to determine which child inherits each railway (or 0 if it is donated to the country).

Input

Input is given as follows:

Output

Output M lines. The i-th line contains the number of the child who inherits railway i, or 0 if it is donated to the country.

Constraints

Subtasks

Sample Input 1

3 5 2
1 2 3
1 2 1
2 3 4
2 3 6
1 3 2

Sample Output 1

1
0
2
1
2

Explanation of Sample Output 1

Sample Input 2

3 6 5
1 2 1
1 2 2
2 3 3
2 3 4
3 1 5
3 1 6

Sample Output 2

4
3
2
1
2
1