using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("3 2 5");
WillReturn.Add("1 2 3");
WillReturn.Add("2 3 3");
WillReturn.Add("2");
WillReturn.Add("3 2");
WillReturn.Add("1 3");
//0
//1
}
else if (InputPattern == "Input2") {
WillReturn.Add("4 0 1");
WillReturn.Add("1");
WillReturn.Add("2 1");
//-1
}
else if (InputPattern == "Input3") {
WillReturn.Add("5 4 4");
WillReturn.Add("1 2 2");
WillReturn.Add("2 3 2");
WillReturn.Add("3 4 3");
WillReturn.Add("4 5 2");
WillReturn.Add("20");
WillReturn.Add("2 1");
WillReturn.Add("3 1");
WillReturn.Add("4 1");
WillReturn.Add("5 1");
WillReturn.Add("1 2");
WillReturn.Add("3 2");
WillReturn.Add("4 2");
WillReturn.Add("5 2");
WillReturn.Add("1 3");
WillReturn.Add("2 3");
WillReturn.Add("4 3");
WillReturn.Add("5 3");
WillReturn.Add("1 4");
WillReturn.Add("2 4");
WillReturn.Add("3 4");
WillReturn.Add("5 4");
WillReturn.Add("1 5");
WillReturn.Add("2 5");
WillReturn.Add("3 5");
WillReturn.Add("4 5");
//0
//0
//1
//2
//0
//0
//1
//2
//0
//0
//0
//1
//1
//1
//0
//0
//2
//2
//1
//0
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => int.Parse(pX)).ToArray();
SplitAct(InputList[0]);
long N = wkArr[0];
long M = wkArr[1];
long L = wkArr[2];
long UB = N;
long[,] KyoriArr = new long[UB + 1, UB + 1];
const long INFTY = long.MaxValue;
// 初期化処理
for (long I = 0; I <= UB; I++) {
for (long J = 0; J <= UB; J++) {
KyoriArr[I, J] = (I == J) ? 0 : INFTY;
}
}
foreach (string EachStr in InputList.Skip(1).Take((int)M)) {
SplitAct(EachStr);
if (wkArr[2] > L) continue;
KyoriArr[wkArr[0], wkArr[1]] = wkArr[2];
KyoriArr[wkArr[1], wkArr[0]] = wkArr[2];
}
// ワーシャルフロイド法 (1回目)
for (long K = 0; K <= UB; K++) {
for (long I = 0; I <= UB; I++) {
if (KyoriArr[I, K] == INFTY) continue;
for (long J = 0; J <= UB; J++) {
if (KyoriArr[K, J] == INFTY) continue;
long CurrKouho = KyoriArr[I, K] + KyoriArr[K, J];
if (KyoriArr[I, J] > CurrKouho) {
KyoriArr[I, J] = CurrKouho;
}
}
}
}
// 補給なしで移動可能なら、コストを1に変更する
for (long I = 0; I <= UB; I++) {
for (long J = 0; J <= UB; J++) {
if (KyoriArr[I, J] > L) KyoriArr[I, J] = INFTY;
if (KyoriArr[I, J] == INFTY) continue;
KyoriArr[I, J] = 1;
}
}
// ワーシャルフロイド法 (2回目)
for (long K = 0; K <= UB; K++) {
for (long I = 0; I <= UB; I++) {
if (KyoriArr[I, K] == INFTY) continue;
for (long J = 0; J <= UB; J++) {
if (KyoriArr[K, J] == INFTY) continue;
long CurrKouho = KyoriArr[I, K] + KyoriArr[K, J];
if (KyoriArr[I, J] > CurrKouho) {
KyoriArr[I, J] = CurrKouho;
}
}
}
}
// クエリに回答する
foreach (string EachStr in InputList.Skip((int)(1 + M + 1))) {
SplitAct(EachStr);
long Kyori = KyoriArr[wkArr[0], wkArr[1]];
if (Kyori == INFTY) {
Console.WriteLine(-1);
}
else {
Console.WriteLine(Kyori - 1);
}
}
}
}