INF = 10**10
n, m, l = gets.split.map(&:to_i)

d = Array.new(n).map{Array.new(n, INF)}

for i in 0...m do
    a, b, c = gets.split.map(&:to_i)
    a -= 1
    b -= 1
    d[a][b] = c
    d[b][a] = c
end

for k in 0...n do
    for i in 0...n do
        for j in 0...n do
            d[i][j] = [d[i][j], d[i][k] + d[k][j]].min
        end
    end
end

for i in 0...n do
    for j in 0...n do
        d[i][j] = 1 if d[i][j] <= l
    end
end

for k in 0...n do
    for i in 0...n do
        for j in 0...n do
            d[i][j] = [d[i][j], d[i][k] + d[k][j]].min
        end
    end
end

q = gets.to_i
q.times do
    s, t = gets.split.map(&:to_i)
    s -= 1
    t -= 1
    puts d[s][t] == INF ? -1 : d[s][t] - 1
end