Under construction

Still being built. Things may change

Alternative Mart

Time limit5sMemory limit512 MB

Summary
For each query, find the closest open discount mart from start region S, skipping up to 10 closed marts, and print its number and the shortest distance.
Level

Medium6 of 10

Topics
Shortest path, Graph, Heap
Solved
No attempts yet

Problem

Minsik lives alone in OJUZ City. OJUZ City has NN regions and MM bidirectional roads, and KK of the NN regions have a discount mart. Region numbers are integers from 1 to NN. At most one road directly connects any two regions, and the two endpoints of every road are different. Any region can reach any other region.

When his work ends, Minsik goes to a discount mart to buy cooking ingredients and snacks, then returns to his apartment. He always takes the fastest route to a discount mart. Sometimes some marts are closed. When a mart is closed, the route he used before may no longer work.

Write a program that finds, for each query, which discount mart Minsik should go to. Ignore the time needed to travel from the mart back home.

Input

The first line contains NN, MM, KK, and QQ, the number of regions, roads, discount marts, and queries. (2≤N≤50 0002 \le N \le 50\,000, N−1≤M≤80 000N-1 \le M \le 80\,000, 1≤K≤N1 \le K \le N, 1≤Q≤50 0001 \le Q \le 50\,000)

The second line contains the KK region numbers with discount marts, in ascending order.

Each of the next MM lines contains two endpoints PiP_i, QiQ_i and the length ViV_i of a road. (1≤Pi,Qi≤N1 \le P_i, Q_i \le N, 1≤Vi≤10 0001 \le V_i \le 10\,000)

Each of the next QQ lines is a query: a start region SS, the number of closed marts XX, and the region numbers C1,…,CXC_1, \ldots, C_X of the closed marts. (0≤X≤min⁡(10,K−1)0 \le X \le \min(10, K-1), 1≤S,Ci≤N1 \le S, C_i \le N)

Output

For each query, print the number of the discount mart Minsik should visit (the region where it is located) and the minimum time to get there. If several marts tie for the shortest time, print the smallest number.

Examples1

  1. Example 1

    Input
    4 5 2 4
    1 4
    1 2 5
    2 4 5
    4 3 5
    3 1 5
    2 3 1
    3 0
    1 1 1
    2 1 4
    4 0
    
    Expected output
    1 5
    4 10
    1 5
    4 0