n, m, l = gets.strip.split.map(&:to_i)

graph=Array.new(n+1) { [2*10**9+1]*(n+1) }
m.times do
  a, b, c = gets.strip.split.map(&:to_i)
  graph[b][a] = graph[a][b] = c if c<= l
end

(n+1).times {|i| graph[i][i]=0 }

(1..n).each do |via|
  (1..n-1).each do |from|
    next if (fv = graph[from][via])>l
    (from+1..n).each do |to|
      next if from==to || via==to

      if graph[from][to] > fv + graph[via][to]
        graph[to][from] = graph[from][to] = fv + graph[via][to]
      end
    end
  end
end

#graph.each {|l|p l}

graph2=Array.new(n+1) { [n+1]*(n+1) }
(1..n).each do |from|
  (from+1..n).each do |to|

    graph2[from][to]=graph2[to][from]=1 if graph[from][to] <= l
    end
  end


(1..n).each do |via|
  (1..n-1).each do |from|
    next if via==from || (fv = graph2[from][via])==n+1

    next if fv == n+1
    (from+1..n).each do |to|
      next if from==to || via==to

      next if graph2[via][to]==n+1

      if graph2[from][to] > fv + graph2[via][to]
        graph2[from][to] = graph2[to][from] = fv + graph2[via][to]
      end
    end
  end
end

#p '---'
#graph2.each {|l|p l}

q=gets.strip.to_i
q.times do
  s, t = gets.strip.split.map(&:to_i)
  r = graph2[s][t]
  p r==(n+1) ? -1 : r-1
end
