#SL2310I. Far Away from Home
Far Away from Home
Far Away from Home
You have decided to move your house to a new place, by a straight road. There are stores lying on the road. The -th store has a distance to the leftmost of the road.
There are types of groceries you need to buy. For each type, your cost to buy it is the distance between your house and the nearest store which sells this. Your total cost is the sum of costs of each type.
Note that even you may buy some types of groceries in the same store, you still need to calculate the distance multiple times.
You need to choose a place for your house to minimize the total cost.
Input
Each test contains multiple test cases. The first line contains an integer denoting the number of test cases.
For each test case, the first line contains two integers $n,c \: (1 \leq n \leq 10^5, 1 \leq c \leq 5 \cdot 10^5)$.
The next lines each, contains two integers and first , denoting the coordinate of store and the number of types of groceries store sells, and following distinct integers $a_{i,1},a_{i,2}, \dots ,a_{i,t_i} (1 \leq a_{i,j} \leq c)$, denoting the types of groceries store sells. It is guaranteed that each appears at least once in all the types the stores sell.
For each test case, it is guaranteed that .
Output
For each test case, output one line with an integer, denoting the minimum total cost.
Example
1
4 4
1 1 4
5 1 4
9 3 1 3 4
2 2 2 3
7