'Hurdles' is a common event in athletics where the runners race in running tracks containing hurdles (obstacles). For the race some hurdles are placed evenly spaced along a straight running course. They are positioned so that they will fall over if bumped into by the runner.
The organizers of 20012 Olympic Games are planning to introduce a hurdles event in swimming. For this purpose, some hurdles will be placed in the swimming pool used in the competition. Let's describe the construction of a swimming pool at first. A pool is L meters long and is divided into K equal sized lanes across the width. Each participant swims along his/her own lane. As events of various lengths take place in the same pool, measurement of length is very critical. So, there is a mark after every meter along the length of the pool starting from 0 in one end. There are some hurdles placed in the pool. A hurdle is placed between two adjacent marks in a lane. Now, the hurdles are not uniformly distributed. For example, in a 5 meter long pool with 2 lanes, the first lane may have 2 hurdles, one between 1m and 2m while another between 3m and 4m. The second lane may have 1 hurdle, between 0m and 1m. For ensuring a fair race, the course must be defined in a way that all the participants have to face the same number of hurdles. In other words, you are to select two length marks from the pool so that there is exactly same number of hurdles placed in every lane between these two length marks. You can safely assume that, a race will always start or end in a length mark.
Input
Input starts with an integer T (≤ 10), denoting the number of test cases.
Each case starts with a line containing two integers L and K (1 ≤ L ≤ 50000, 1 ≤ K ≤ 30). Each of the next K lines describes a lane. Each of these lines starts with an integer n (1 ≤ n ≤ 5000) denoting the number of hurdles in the lane, followed by n distinct integers. The ith integer pi (0 ≤ pi < L) denotes that there is a hurdle between length mark pi and pi+1.
Output
For each case, print the case number and the length of the longest race that can take place in the pool.
Sample
Sample Input | Sample Output |
---|---|
2 5 2 2 1 3 2 0 2 5 3 3 0 3 4 2 0 3 2 3 4 | Case 1: 5 meter(s) Case 2: 3 meter(s) |
Notes
Dataset is huge, use faster I/O methods.