Because of various strange viruses spreading around, every member of the International Confederation of Revolver Enthusiasts (ICORE) must undergo a quarterly physical checkup at General Hospital. All checkups are arranged by the boss and scheduled on the same day. Each member receives instructions that give:
The doctors' offices are numbered {1, ..., m}.
Everyone was told the schedule was prepared professionally so that no one would have to line up and wait. Reality was different: queues formed quickly. The members are all disciplined and follow these rules:
Determine the time at which the last visitor leaves the hospital.
The first line contains a natural number c, the number of test cases. Each test case follows in the format below.
The first line of a case contains two natural numbers n and m (1 ≤ n, m ≤ 1000): the number of visitors and the number of doctors' offices. Each of the next n lines describes one visitor. Line i (1 ≤ i ≤ n) has the form
t k g_1 g_2 ... g_k
meaning that visitor i arrives at time t and must visit k offices in the order g_1, g_2, ..., g_k, where 1 ≤ g_j ≤ m. It is guaranteed that 0 ≤ t ≤ 1000000 and that no more than 1000000 visits are scheduled for the whole day.
For each of the c test cases, print a single line with the time at which the last visitor leaves the hospital.