Global firefighters

A new criminal group named Arsenists Without Borders are lighthing fires all over the world with a special chemical composition that makes the fires hard to neutralize. So, in order to protect people, during the last UN reunion it was decided to create a global unit of firefighters. But now they need some nice slogans about how good are the firefighters. Explicitely, they want to advertise how much time it will take them to get to some locations.

Input

Input starts with the number of cases. Every case begins with the number of cities nn and the number of roads mm. Follow mm triples (u,v,d)(u, v, d) to indicate a bidirectional road from uu to vv (with uvu \ne v) of length d>0d > 0. Afterwards, we have a number kk, followed by kk different cities where the firefighter units are located. Finally, we have the number of queries qq for this case, followed by qq numbers of a city (numbered from 0 to n1n - 1). You can suppose that the map is connected, and that there is at most one single road directly connecting two cities. Assume 0<n1050 < n \le 10^5, n1m30nn-1 \le m \le 30n, 0<kmin(n,1000)0 < k \le \min(n, 1000), and 0<q10000 < q \le 1000.

Output

For every case, print first its number starting at one. Afterwards, for each query, provide the distance between the city and the closest firefighter unit, and in which city it is located (in case of a tie, print the lowest number). Separate the output for two cases with a blank line.

Problem information

Author: Francesc Martínez

Generation: 2026-01-25T11:20:06.452Z

© Jutge.org, 2006–2026.
https://jutge.org