lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
M = lines[0][1]
L = lines[0][2]
Inf = 10 ** 15

dist = []
for i in 1..N do   #access & distance: same order
  dist[i-1] = []
  for j in 1..N do
    if i != j then
      dist[i-1][j-1] = Inf
    else
      dist[i-1][j-1] = 0
    end
  end
end
for i in 1..M do
  from = lines[i][0]
  to = lines[i][1]
  dist[from-1][to-1] = lines[i][2]
  dist[to-1][from-1] = lines[i][2]
end

for k in 1..N do
  for i in 1..N do
    for j in 1..N do
      if dist[i-1][j-1] > dist[i-1][k-1] + dist[k-1][j-1] then
        dist[i-1][j-1] = dist[i-1][k-1] + dist[k-1][j-1]
      end
    end
  end
end

dist2 = []
for i in 1..N do
  dist2[i-1] = []
  for j in 1..N do
    if i == j then
      dist2[i-1][j-1] = 0
    elsif dist[i-1][j-1] <= L then
      dist2[i-1][j-1] = 1
    else
      dist2[i-1][j-1] = Inf
    end
  end
end
    
for k in 1..N do
  for i in 1..N do
    for j in 1..N do
      if dist2[i-1][j-1] > dist2[i-1][k-1] + dist2[k-1][j-1] then
        dist2[i-1][j-1] = dist2[i-1][k-1] + dist2[k-1][j-1]
      end
    end
  end
end
  
Q = lines[M+1][0]
for i in 1..Q do
  from = lines[M+i+1][0]
  to = lines[M+i+1][1]
  puts dist2[from-1][to-1] - 1
end