Jogging in the Park

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

문제

The Outer Park is very well suited for jogging. Inside the park, there are nn glades, conveniently numbered from 1 to nn. The glades are connected by mm trails, the ii-th trail connects glades a_ia\_i and b_ib\_i and has length c_ic\_i meters. All trails can be walked in both directions. The main entrance is situated at glade 1.

Your friends decided to have a nice run together over the park. Each of them prepared her own route starting from the entrance and moving to subsequent glades by trails.

At the end of jogging, all your friends want to reach glade nn with a beautiful cafe at the same time. Not everyone planned her route accordingly, though: some of the routes do not end at glade nn, and the routes might have different length as well. Luckily, all your friends run at the same speed.

You decided to help your friends and write a program to provide each of them with an extended route --- that is, a route which starts with the same sequence of glades as her original one, but ends at glade nn and has exactly the same length, in meters, as all the other extended routes. Note that both the original and the extended routes may contain the same trail multiple times.

입력

The first line of the input contains two integers nn and mm (2n502 \le n \le 50; 1mn(n1)21 \le m \le \frac{n(n-1)}{2}) --- the number of glades and trails in the park. Each of the next mm lines contains three integers a_ia\_i, b_ib\_i and c_ic\_i (1a_i,b_in1 \le a\_i, b\_i \le n; a_ib_ia\_i \ne b\_i; 1c_i1061 \le c\_i \le 10^6) --- the indices of glades connected by the ii-th trail and its length, respectively.

The next line of the input contains a single integer kk (2k502 \le k \le 50) --- the number of your jogging friends. Each of the next kk lines contains an integer l_il\_i (2l_i502 \le l\_i \le 50) --- the number of glades in the route of your ii-th friend, followed by l_il\_i integers g_i,1,g_i,2,,g_i,l_ig\_{i,1}, g\_{i,2}, \ldots, g\_{i,l\_i} (1g_i,jn1 \le g\_{i,j} \le n) --- the indices of glades in the route.

All unordered pairs (a_i,b_i)(a\_i, b\_i) are distinct. For every ii, g_i,1=1g\_{i,1} = 1. For every jj between 11 and l_i1l\_i - 1, there exists a trail between glades g_i,jg\_{i,j} and g_i,j+1g\_{i,j+1}.

출력

If it is impossible to extend all the routes according to the problem statement, output a single integer 1-1. Otherwise, print kk lines. The ii-th of these lines must contain an integer p_ip\_i (p_il_ip\_i \ge l\_i) followed by p_ip\_i integers h_i,1,h_i,2,,h_i,p_ih\_{i,1}, h\_{i,2}, \ldots, h\_{i,p\_i} (1h_i,jn1 \le h\_{i,j} \le n) --- the indices of glades in the ii-th extended route.

For every ii, h_i,p_ih\_{i,p\_i} must be equal to nn. For every jj between 11 and p_i1p\_i - 1, there must exist a trail between glades h_i,jh\_{i,j} and h_i,j+1h\_{i,j+1}. For every jj between 11 and l_il\_i, h_i,jh\_{i,j} must be equal to g_i,jg\_{i,j}. The total length of all the extended routes, in meters, must be the same.

The sum of all p_ip\_i must not exceed 21062 \cdot 10^6. It is guaranteed that if a valid route extension exists, there also exists one with the sum of all p_ip\_i not exceeding 21062 \cdot 10^6.