n, m, l = gets.strip.split.map(&:to_i)
abc = m.times.map { gets.strip.split.map(&:to_i) }

q=gets.strip.to_i
st=q.times.map { gets.strip.split.map(&:to_i) }

INF=10**11

graph=Array.new(n+1) { [INF]*(n+1) }
abc.each do |a, b, c|
  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).each do |from|
    fv = graph[from][via]
    (from+1..n).each do |to|
      next if from==to || via==to
      vt = graph[via][to]

      if graph[from][to] > fv + vt
        graph[to][from] = graph[from][to] = fv + vt
      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).each do |from|
    next if via==from
    fv = graph2[from][via]

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

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

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

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


st.each do |s,t|
  r = graph2[s][t]
  p r==(n+1) ? -1 : r-1
end


