We have k integers from 1 to k. Now give
you n sequences. The ith element of the sequence can change to the (i+1)th
element (the last one cannot be changed). The element can change from one
sequence to another sequence. There are q queries. Each query will give you an
integer x. Please find the minimum change steps for changing x to itself.
Note: The change steps should be positive.
If an integer cannot change to itself, print -1.
The first line will be an integer T. (1
<= T <= 50) T is the number of test cases.
For each test case, the first line will be
three integers k, n and q. (1 <= k, n <= 200, q <= 10000)
Then there will be n lines. Each line begins
with an integer t (1 <= t <= 200). t is the length of this sequence. Then
t integers in the line is the elements in this sequence.
Then there is an integer q. q is the number
of queries.
For each query, there will be an integer x.
For each query, print the step problem
required.
For 1, 1->3 (in sequence 1)
3->1 (in sequence 3) the answer is 2.
For 2, 2 can be changed to 4, and 4 can be
changed to 6. But 6 and 4 cannot change to 2.