| Thanks to his tireless hard work, Wilson has been promoted and now gets to | |
| drive his moving company's trucks! No, he can't believe it either. | |
| The moving company services a region that has **N** towns, with **M** roads | |
| running amongst them. The _i_th road connects two different towns **Ai** and | |
| **Bi**, requires **Gi** litres of gas to drive along, and can be traversed in | |
| either direction. There may be multiple roads running directly between any | |
| given pair of towns. | |
| Today, Wilson has been scheduled to transport **K** families' belongings. The | |
| _i_th family is moving from town **Si** to a different town **Di**. Wilson and | |
| his truck will be starting off the day at the company headquarters in town 1. | |
| For each family, he'll need to drive to their starting town by following a | |
| sequence of roads, load his truck there, and at some point later, arrive at | |
| their destination town to unload their belongings. His truck is large enough | |
| to fit at most 2 families' sets of belongings at a time, meaning that he | |
| doesn't necessarily need to deliver each load immediately after picking it up. | |
| However, Wilson has been instructed that the **K** families must be helped | |
| strictly in order. In particular, if i < j, then the _i_th family's belongings | |
| must be loaded before the _j_th family's belongings are loaded, and the _i_th | |
| family's belongings must be delivered before the _j_th family's belongings are | |
| delivered. | |
| Although Wilson's wages are higher than ever, he does have to pay for the | |
| truck's gas out of his own pocket, so it's in his best interest to get the job | |
| done while burning through as little of it as possible. Of course, he'll still | |
| need to be careful to follow his company's strict rules regarding the relative | |
| order of the families' loads and unloads, to avoid getting fired. That being | |
| said, it's a possibility for it to be impossible to even complete all of the | |
| requested moves, in which case Wilson will simply call it a day and stay home | |
| instead. | |
| ### Input | |
| Input begins with an integer **T**, the number of sets of families Wilson | |
| needs to move. | |
| For each case, there is first a line containing three space-separated | |
| integers, **N**, **M**, and **K**. | |
| Then, **M** lines follow, the _i_th of which contains 3 space-separated | |
| integers, **Ai**, **Bi**, and **Gi**. | |
| Then, **K** lines follow, the _i_th of which contains 2 space-separated | |
| integers, **Si** and **Di**. | |
| ### Output | |
| For the _i_th case, print a line containing "Case #**i**: " followed by the | |
| minimum amount of gas required for Wilson to validly complete his delivery | |
| schedule, or -1 if it can't be done. | |
| ### Constraints | |
| 1 ≤ **T** ≤ 100 | |
| 2 ≤ **N** ≤ 100 | |
| 1 ≤ **M** ≤ 5,000 | |
| 1 ≤ **K** ≤ 5,000 | |
| 1 ≤ **Ai**, **Bi** ≤ **N**, **Ai** ≠ **Bi** | |
| 1 ≤ **Si**, **Di** ≤ **N**, **Si** ≠ **Di** | |
| 1 ≤ **Gi** ≤ 1,000 | |
| ### Explanation of Sample | |
| In the first case, Wilson drives to town 2, and then drives the first family's | |
| belongings back to town 1. That's 8 litres gas so far. Then Wilson drives to | |
| city 3 (11 more litres of gas), picks up the remaining belongings, and drives | |
| them all to town 2 (7 litres of gas). A grand total of 8 + 11 + 7 = 26 litres | |
| of gas. | |
| In the fourth case, Wilson can't reach town 4 in order to complete the 2nd and | |
| 3rd families' moves. | |