G. Graph Passage
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There is a directed road network with $$$N$$$ nodes and $$$M$$$ weighted edges, where you are at node $$$1$$$. Your car has battery capacity $$$C$$$, and also starts with $$$C$$$ battery.

Each edge in the graph either increases or decreases your battery when you traverse it. When you have $$$x$$$ battery, you can traverse an edge with weight $$$w$$$ if and only if $$$x \geq w$$$. After traversing such an edge, you will have $$$\min(C, x - w)$$$ battery. Some edges may even be negative, thus increasing your battery.

You want to know the following: which nodes can you reach from your starting node? For each node you can reach, what is the maximum amount of battery you can have when you reach it?

Input

The first line contains $$$T(1 \le T \le 50)$$$, the number of testcases. Then the test cases follow, each with the following format:

  • The first line contains three space-separated integers: $$$N(1 \le N \le 100)$$$, $$$M(1 \le M \le 500)$$$, and $$$C(0 \le C \le 5 \cdot 10^{17}$$$, the number of nodes, number of edges and the battery capacity respectively.
  • $$$i^{\text{th}}$$$ of the next $$$M$$$ lines contains three space separated integers, $$$U_i, V_i (1 \le U_i, V_i \le N)$$$ and $$$W_i (-10^{15} \le W_i \le 10^{15})$$$, indicating a directed edge from $$$U_i$$$ to $$$V_i$$$ with weight $$$W_i$$$.
Output

For each testcase, print $$$N$$$ space-separated integers on a new line. The $$$i^{\text{th}}$$$ of these integers should denote the maximum possible battery you can have when you reach node $$$i$$$, or $$$-1$$$ if it is impossible.

Example
Input
2
6 6 11
1 2 3
1 3 2
2 3 5
3 4 4
4 5 7
4 6 1
6 6 11
1 3 2
1 2 3
2 3 5
3 4 -9
4 5 12
4 6 10
Output
11 8 9 5 -1 4 
11 8 9 11 -1 1