Year of More Code Jam (Small)

No attempts yetTime limit5sMemory limit512 MB

Problem

A new year brings a new calendar and new challenges. Some things do not change. Plenty of good programming contests are still scheduled, and Sphinny still loves them.

Sphinny follows several tournaments. Each tournament consists of a number of rounds. The organizer of a tournament has not fixed the start date yet, but has already fixed how many rounds there are and how many days after the start date each round falls on.

Rounds from different tournaments can land on the same day. Sphinny is happier when more rounds land on one day. For every day that holds SS rounds, her happiness grows by S2S^2. Her happiness starts at 0.

The picture below shows three tournaments, one color each, and Sphinny's total happiness is 20. One tournament starts on day 2 of the year, one starts on day 5, and one starts on day 6.

Rounds of three tournaments placed on a calendar

The year has NN days. Each tournament starts on one of those NN days, and every starting day is equally likely. Compute the expected value of Sphinny's happiness.

Sphinny wants the exact value, not an approximation. There are TT tournaments, so there are NTN^T equally likely ways to choose the start dates. Write the expected happiness as K+A/BK + A/B, where KK and BB are positive integers and AA is a non-negative integer smaller than BB. If AA is 0 then BB must be 1, and otherwise the greatest common divisor of AA and BB must be 1.

A tournament that starts late enough pushes some of its rounds into the next year. Those rounds add nothing to Sphinny's happiness this year.

Input

The first line holds one integer CC, the number of test cases. The first line of each test case is

N T

where NN is the number of days in the year and TT is the number of tournaments. TT lines follow, one per tournament, in the format

m d2 d3 ... dm

The tournament has mm rounds, and its ii-th round is held on day did_i of the tournament. The first round is always held on day 1, so d1=1d_1 = 1 is not part of the input and exactly m1m - 1 numbers follow mm.

Limits

  • 1C501 \le C \le 50
  • 1N1091 \le N \le 10^9
  • 1T31 \le T \le 3
  • 2m502 \le m \le 50
  • 1<d2<d3<<dm100001 < d_2 < d_3 < \cdots < d_m \le 10000

Output

For each test case, print one line in the format

Case #X: K+A/B

where XX is the test case number starting from 1, and KK, AA and BB are the values described above.