There was a strange city with n junctions connected by m bidirectional roads. Even though the rapid growth of ride-sharing companies became a blessing for the general public, it also became a nightmare for the traditional taxi companies. So, they decided to come up with a scheme to stop this immense growth.
For simplicity, assume that a driver earns a static wi amount passsing a road. Roads form loops, loop is a set of distinct junctions j1, j2, …, jk except j1 = jk, k > 3 and (ji, ji + 1) (1 ≤ i < k) are connected by a road.
For each road, they want to set a minimum amount of toll (integer) such that there exists a loop containing the road and if a driver visits the roads in that loop in the same order, he/she needs to pay more tolls than the total earned money in the loop.
Input
Input starts with a positive integer T (≤ 50), denoting the number of test cases.
Each case starts with a blank line. The next line contains two integers n m (1 ≤ n ≤ 200, 0 ≤ m). Assume that the junctions are identified as integers. Each of the next m lines will contain three integers u v w (0 ≤ u, v < n, u ≠ v, 0 < w ≤ 200), meaning that a driver earns w if he/she visits road connecting junction u and v. There is at most one road between any two junctions.
Output
For each case, print the case number in a single line. Then for each road in the city (in the order of input), print the minimum possible toll for that road. If it's not possible, print impossible
.
Sample
Sample Input | Sample Output |
---|---|
2 4 4 0 1 10 1 2 20 0 3 15 3 2 16 5 6 0 1 10 1 2 20 0 3 15 3 2 16 0 4 9 1 3 11 | Case 1: 52 42 47 46 Case 2: 27 28 22 32 impossible 26 |
Notes
- Dataset is huge, use faster I/O methods.
For case 1, for the first road 0 - 1, if a toll of 52 is set to the road, then if a driver passes 0 - 1 - 2 - 3 - 0 (earning: -52 + 20 + 16 + 15 = -1); he/she is paying more toll than earning. |
|
For case 2, for the second road 1 - 2, if a toll of 28 is added to the road, then if a driver passes 3 - 1 - 2 - 3 (earning: 11 - 28 + 16 = -1); he/she is paying more toll than earning. |