Let`s Go Green
Khairy is a young, smart and highly talented politician. However, he still believes that for success, and especially to obtain something, one's network of personal contacts is essential. Next month will be the Supreme Council election of his political party. He wants to contest and really hope to win in the election. Therefore, support from top influential politician is needed.
Time is running out, therefore he plans a strategy. If he cannot meet the top person directly he will use other politicians to introduce him to this top leader. In order to do this, he models the strength of relationship among the politicians.
The strength of relationship between two people is represented as follows: Faithful (1), Close (2), Buddies (3) and Acquaintance (4). Between two politicians, either one of them will normally stimulate the communication. No representation for enemy. It will be much better if a faithful friend introduces Khairy to someone rather than an acquaintance. So Khairy wants to minimize the sum of strength of the relations he is using to meet the top influential politician.
From a list of N politicians, given their relationship strengths, find a list of politicians so that Khairy meets the top influential politician through them while the sum of strength of all the relationships he used is minimized.
Your task is to come out with a sequence of politicians that Khairy needs to meet in order to get introduced to the top influential politician.
Input
The first line of input is T which is the number of cases, 1 < T < 1000. This is followed by the test cases. Each case consists of several lines. The first line contains 2 numbers, first is N which represents the number of relationships, N ≤ 200, and M which represents the number of politicians, 5 ≤ M ≤ 20. Each of the next N lines contains three integers that represent politician x, his/her friend y (0 ≤ x, y < M) and the strength of relationship z (1 ≤ z ≤ 4). Politician x=0 represents Khairy and politician x=M-1 represents the top politician.
Output
For each test case, the output contains a line in the format Case #x: where x is the case number (starting from 1) followed by a colon, followed by a sequence of politicians to meet. If there is multiple valid sequence of politicians print any of them. The list must start with 0 (Khairy's id) and end with M-1, the top politician. If there is no way Khairy can meet the to politician, print -1.
Explanation for the first case: Khairy can ask politician 1 (strength 2, close) to introduce him to politician 3 (strength 4, acquaintance), who can finally introduce Khairy to politician 4 (strength 4, acquaintance). In that way total strength used in this situation is 2+4+4 = 10.
Khairy can straightly talk to politician 4 (strength 3, buddy). But instead if Khairy asks politician 2 (strength 1, faithful) to introduce him to politician 4 (strength 1, again faithful) – the total strength used in this situation is 2, which is better than the other two situations and Khairy is more likely to make a good impression.