Petrol

Given a weighted graph with some marked stations, answer queries asking whether a tanker of capacity b can travel from station x to station y, refuelling only at stations.

Hard8GraphShortest pathUnion-findSortingNo attempts yetTime limit2sMemory limit512 MB

Problem

Byteasar works in the logistics department of Byteoil, the petroleum company of Byteotia. His job is to plan fuel deliveries to petrol stations.

Byteotia has nn intersections, numbered from 11 to nn, and mm two-way roads, each connecting a pair of intersections. Some intersections have a Byteoil petrol station.

The Byteoil transport fleet consists of tankers with fuel tanks of various capacities. A tanker burns 11 litre of petrol per kilometre travelled, so a tanker whose tank holds bb litres can cover at most bb kilometres without refuelling. Drivers cannot use the fuel carried as cargo, but they can fill the tank free of charge at any Byteoil petrol station.

Byteasar's work consists of answering the following query over and over: can a tanker with a tank of capacity bb litres drive from the petrol station at intersection xx to the petrol station at intersection yy? A tanker with a tank of capacity bb litres cannot drive more than bb kilometres without passing a Byteoil petrol station. Every trip starts at an intersection with a Byteoil petrol station and ends at an intersection with a Byteoil petrol station.

Help Byteasar answer his logistic queries automatically.

Input

The first line contains three integers nn, ss and mm (2sn2000002 \le s \le n \le 200\,000, 1m2000001 \le m \le 200\,000): the number of intersections, the number of petrol stations and the number of roads in Byteotia. The second line contains ss pairwise distinct integers c1,c2,,csc_1, c_2, \ldots, c_s (1cin1 \le c_i \le n), the intersections with a Byteoil station.

The next mm lines describe the roads. The ii-th of these lines contains three integers uiu_i, viv_i and did_i (1ui,vin1 \le u_i, v_i \le n, uiviu_i \ne v_i, 1di100001 \le d_i \le 10\,000): the ii-th road is did_i kilometres long and connects intersection uiu_i with intersection viv_i. Each pair of intersections is connected by at most one road.

The next line contains one integer qq (1q2000001 \le q \le 200\,000), the number of queries. Each of the following qq lines describes one query. The ii-th of these lines contains three integers xix_i, yiy_i and bib_i (1xi,yin1 \le x_i, y_i \le n, xiyix_i \ne y_i, 1bi2×1091 \le b_i \le 2 \times 10^9), asking whether a tanker with a tank of capacity bib_i litres can drive from the petrol station at intersection xix_i to the petrol station at intersection yiy_i. Both intersections xix_i and yiy_i have a Byteoil petrol station.

Output

Print exactly qq lines. The ii-th line contains the single word TAK (yes) if a tanker with a tank of capacity bib_i litres can drive from intersection xix_i to intersection yiy_i, and NIE (no) otherwise.