# Class Schedule

Time Limit: 10 Seconds Memory Limit: 131072 KB

At Fred Hacker's school, there are T × C classes, divided into C catagories of T classes each. The day begins with all the category 1 classes being taught simultaneously. These all end at the same time, and then all the category 2 classes are taught, etc. Fred has to take exactly one class in each category. His goal is to choose the set of classes that will minimize the amount of "energy'' required to carry out his daily schedule.The energy requirement of a schedule is the sum of the energy requirement of the classes themselves, and energy consumed by moving from one class to the next through the schedule. More specifically, taking the jth class in the ith category uses E_{ij} units of energy. The rooms where classes take place are located at integer positions (ranging from 0 to L) along a single hallway. The jth class in the ith category is located at position P_{ij}. Fred starts the day at position 0, moves from class to class, according to his chosen schedule, and finally exits at location L. Moving a distance d uses d units of energy.Fred starts the day at position 0, moves from class to class, according to his chosen schedule, and finally exits at location L. Moving a distance d uses d units of energy.

## Input

The first line of the input is Z ≤ 20 the number of test cases. This is followed by Z test cases. Each test case begins with three space-separated integers: C, T, and L. Each of the following C× T lines gives, respectively, the location and energy consumption of a class. The first T lines represent the classes of category 1, the next T lines represent the classes of category 2, and so on. No two classes in the same category will have the same location. lines represent the classes of category 2, and so on. No two classes in the same category will have the same location.

1 ≤ C ≤ 25

1 ≤ T ≤ 1000

1 ≤ L ≤ 1,000,000

1 ≤ E_{ij} ≤ 1,000,000

0 ≤ P_{ij} ≤ L

## Output

For each input instance, the output will be a single integer on a line by itself which is the minimum possible energy of a schedule satisfying the constraints.

## Sample Input

1 3 2 5 2 1 3 1 4 1 1 3 1 4 3 2

## Sample Output

11Submit

Source: University of Waterloo Local Contest 2011.10.02