A party has been arranged for n richest people of the city "Richtown". They have set some strange rules such that only rich people can join the party. Also, when a person enters the party, he/she is given two cards - entrance and exit represented as (x, y), where x is the integer written on the entrance card, and y is the integer written on the exit card. No two persons can have entrance (or exit) cards with the same integers written on them. When a person exits the party, he/she has to pay the dollar equivalent to the absolute difference of the integers in his entrance and exit cards.
Though they were rich, they were intelligent and came up with a plan to exchange their cards in such a way that the total money paid by them is as low as possible. Any people can exchange cards multiple times and with multiple persons. But the entrance cards are distinguishable from the exit cards, so entrance cards are only exchangeable with entrance cards, and the same rule applies for exit cards.
For example, suppose there are three people having cards with (1, 5), (7, 3), (8, 10), then if they don't exchange cards, they have to pay |1-5| + |7 - 3| + |8 - 10| = 10$. But if they exchange them to (1, 3), (7, 5), (8, 10) then they need to pay |1-3| + |7-5| + |8-10| = 6$. But there is one problem, each person must pay at least K$ otherwise, the organizers will suspect that they have been cheating. So, your job is to help them find a solution where they have to pay as little as possible without creating any suspicion.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case starts with a blank line. Next line contains two integers n (1 ≤ n ≤ 10000) and K (0 ≤ K ≤ 2). Each of the next n lines contains two integers (between 1 and 50000) denoting the integers written on the entrance and exit cards respectively for ith person.
Output
For each case, print the case number and the minimum amount of money they need to pay. If its impossible to do so, print impossible
.
Sample
Sample Input | Sample Output |
---|---|
2 3 1 1 1 7 3 8 10 1 2 10 9 | Case 1: 10 Case 2: impossible |
Notes
Dataset is huge, use faster I/O methods.