There are several cities in the country - Zen, and some bidirectional roads are connecting them. Unfortunately, some of the roads are damaged and are unusable right now. Your goal is to rebuild enough of the damaged roads so that there is a functional path between every pair of cities.
You are given the description of roads. Damaged roads are formatted as city1 city2 cost" and non-damaged roads are formatted as "city1 city2 0". In this notation city1 and city2 are the case-sensitive names of the two cities directly connected by that road. If the road is damaged, there is a cost of rebuilding that road. Every city in Zen will appear at least once in the given input. And there can be multiple roads between same pair of cities.
Your task is to find the minimum cost of the roads that must be rebuilt to achieve the given goal. If it is impossible to do so, print Impossible
.
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case begins with a blank line and an integer m (1≤ m ≤ 50) denoting the number of roads. Then there will be mlines, each containing the description of a road. No names will contain morethan 50 characters. The road costs will lie in the range [0, 1000].
Output
For each case of input you have to print the case number andthe desired result.
Sample
Sample Input | Sample Output |
---|---|
2 12 Dhaka Sylhet 0 Ctg Dhaka 0 Sylhet Chandpur 9 Ctg Barisal 9 Ctg Rajshahi 9 Dhaka Sylhet 9 Ctg Rajshahi 3 Sylhet Chandpur 5 Khulna Rangpur 7 Chandpur Rangpur 7 Dhaka Rajshahi 6 Dhaka Rajshahi 7 2 Rajshahi Khulna 4 Kushtia Bhola 1 | Case 1: 31 Case 2: Impossible |