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

1.upto(n) do |k|
    1.upto(n) do |s|
        next if road[s][k] > l

        1.upto(n) do |f|
            if road[s][f] > road[s][k] + road[k][f]
                road[s][f] = road[s][k] + road[k][f]
            end
        end
    end
end

x = Array.new(n+1){Array.new(n+1,10000)}
1.upto(n) do |i|
    1.upto(n) do |j|
        x[i][j] = 1 if road[i][j] <= l
    end
end

1.upto(n) do |k|
    1.upto(n) do |s|
        next if x[s][k] == 10000

        1.upto(n) do |f|
            if x[s][f] > x[s][k] + x[k][f]
                x[s][f] = x[s][k] + x[k][f]
            end
        end
    end
end

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