We apologize for any inconvenience

아직 제출이 없습니다시간 제한10초메모리 제한512 MB

문제

Studying at the Jagiellonian University in Krakow has its pros and cons. Pros: Jagiellonian University. Cons: Krakow... Or, more precisely, a constant necessity to deal with tram track reconstructions.

Initially, the public transport network consists of some number of tram lines. Then one of them gets suspended, then another one, and then another... As you may know yourself, the inviolable rule in Krakow is to always suspend a line before any of the previously suspended lines resumes its operation. Right now not all of the lines have been suspended (yet), and you sit in a tram, annoyed that your direct connection to the university has just disappeared. You look out of the window and you ask yourself: "Am I actually the most unlucky passenger in this city? Or is there someone out there somewhere who needs to change lines even more times in order to get where they want?"

More precisely, we say that stop BB is reachable from stop AA with cc changes if there exist lines l_0,,l_cl\_0, \ldots, l\_c such that l_0l\_0 serves stop AA, l_cl\_c serves stop BB, and for each 0i<c0 \leq i < c there exists some stop served by l_il\_i and l_i+1l\_{i+1}. At each point in time, you want to know the largest value of cc such that there exists a pair of stops (A,B)(A, B) where BB is reachable from AA with cc changes and BB is not reachable from AA with cc' changes for any c\<cc'\<c.

Note that sometimes it might not be possible to travel between a pair of stops at all. As follows from the definition above, you decide not to take such pairs into consideration in your analysis -- you conclude that if someone wishes to travel between those stops, they will take an Uber anyway.

입력

The first line of input contains the number of test cases zz (1z351 \leq z \leq 35). The descriptions of the test cases follow.

The first line of each test case contains the number of stops nn and the number of tram lines kk (2n,k7502 \leq n, k \leq 750). The stops are numbered from 11 to nn and the lines are numbered from 11 to kk.

Then, kk lines follow. The ii-th of those lines describes the route of the tram line number ii. Each line starts with an integer r_ir\_i (2r_in2 \leq r\_i \leq n) followed by r_ir\_i distinct integers a_i,ja\_{i, j} (1a_i,jn1 \leq a\_{i,j} \leq n) -- the identifiers of stops served by the ii-th tram line.  Any tram line runs in both directions.

The next line contains a single integer ss (1sk11 \leq s \leq k -1).

Then, ss lines follow, describing the order in which the tram lines get suspended. Each of those lines contains a single integer s_is\_i (1s_ik1 \leq s\_i \leq k) -- the identifier of the suspended tram line. Any line can get suspended at most once.

The sums of values of nn and kk in all test cases do not exceed 1000 each.

출력

For each test case, output s+1s+1 lines, each containing a single integer. The i+1i+1-th line should denote the largest number of line changes necessary after the ii-th suspension event (the first line denoting the answer before any suspensions).

힌트

Initially, one line change is required to travel, for example, from stop 4 to stop 5 (or vice versa). Such travel is possible by taking line 2, then line 1. There are no pairs of stops requiring 2 or more changes.

After line 1 gets removed, two line changes are required to travel from stop 1 to stop 3 (or vice versa).

When lines 1 and 4 get removed, the only pairs of stops still reachable one from another are (1, 4) and (2, 3), and in both cases no line changes are required to travel between them.

When lines 1, 4 and 3 get removed, the only pair of stops still reachable one from another is (1, 4). No line changes are required to travel between these stops.