PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FW0000104. Du lịch bằng ô tô (Travel by Car)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Du lịch bằng ô tô (Travel by Car)

Travel by Car

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn cities with undirected roads. The car starts with a full tank of capacity LL and consumes one fuel unit per distance unit. It may refill to full at any city. For each query s,ts,t, find the minimum number of refills at intermediate cities, or -1 if the journey is impossible. No refill at the destination is counted.

Input

First line: n,m,Ln,m,L; next mm lines contain undirected roads u,v,wu,v,w; then integer qq followed by qq queries s,ts,t. Vertices are 1-indexed.

Output

Print one integer per query: minimum refills, or -1.

Subtasks

  • Subtask 1 (40 points): 2≤n≤6,  1≤q≤8,  2≤L≤252\le n\le 6,\;1\le q\le 8,\;2\le L\le 25. All input-format and graph conditions above apply.

  • Subtask 2 (60 points): 2≤n≤16,  1≤q≤25,  2≤L≤702\le n\le 16,\;1\le q\le 25,\;2\le L\le 70. All input-format and graph conditions above apply.

Examples

Input

3 2 5
1 2 4
2 3 4
3
1 3
1 2
1 1

Output

1
0
0

Explanation

The trip 1 to 3 has two legs of length 4 and needs one refill at city 2. From 1 to 2 needs none, and staying at city 1 needs none.