Alice wants to send Bob some confidential messages. But their internet connection is not secured enough. As their names have been used in many networking schemes, they are very rich now. So, they don't want to send encoded messages, they want to use secured dedicated connection for them. So, they talked to some ISPs (Internet Service Providers) about their problem. Only they get is that there are N routers in the network, some of them share bidirectional links. Each link has a capacity, and for each KB of data passing through this link, they have to pay some money. Assume that Alice is connected with the 1st router and Bob is connected to the Nth router.
For example, in the picture, Alice wants to send 4 KB data from router 1 to router 6. Each link is identified by two integers in the form (a, b) where 'a' denotes the capacity of the link and 'b' denotes per KB cost of the link. So, Alice can send 1KB of data through 1 - 2 - 3 - 4 - 6 (cost 8), 2KB data through 1 - 5 - 6 (cost 2 * 9=18) and 1KB data through 1 - 3 - 4 - 6 (cost 11). So, the total cost is 37 units.
Now Alice wants to send P KB of data to Bob. You have to find the minimum amount of money they have to pay to achieve their goal.
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case starts with a blank line. Next line contains three integers N (2 ≤ N ≤ 50), M (0 ≤ M ≤ N*(N-1)/2) and P (1 ≤ P ≤ 1000), where M denotes the number of bidirectional links. Each of the next M lines contains four integers u v w c (1 ≤ u, v ≤ N, u ≠ v, 1 ≤ w, c ≤ 100), meaning that there is a link between router u and v, and at most c KB data can be sent through this link, and each KB of data through this link will cost w. You can assume that there will be at most one connection between a pair of routers.
Output
For each case, print the case number and the minimum amount of money required or impossible
if it's not possible to send P KB of data.
Sample
Sample Input | Sample Output |
---|---|
3 6 9 4 3 1 9 8 1 2 1 2 1 5 6 1 5 6 2 8 6 4 2 2 4 2 7 6 2 6 7 9 3 4 5 1 3 2 2 3 6 9 9 3 1 9 8 1 2 1 2 1 5 6 1 5 6 2 8 6 4 2 2 4 2 7 6 2 6 7 9 3 4 5 1 3 2 2 3 4 4 20 1 3 1 3 3 4 1 4 1 2 1 2 2 4 1 5 | Case 1: 37 Case 2: 139 Case 3: impossible |