# after reading explanation
n, m, l = gets.split.map(&:to_i)
INF = 1000000007
@dist = []
n.times{ @dist << Array.new(n, INF) }
@dist2 = []
n.times{ @dist2 << Array.new(n, INF) }
m.times{
  a, b, c = gets.split.map(&:to_i)
  @dist[a-1][b-1] = c
  @dist[b-1][a-1] = c
  @dist2[a-1][b-1] = 1
  @dist2[b-1][a-1] = 1
}
# WarshallFloyd
n.times{|i|
  n.times{|j|
    n.times{|k|
      @dist[i][j] = @dist[i][k] + @dist[k][j] if (@dist[i][j] > @dist[i][k] + @dist[k][j])
    }
  }
}
n.times{|i|
  n.times{|j|
    if @dist[i][j] <= l
      @dist2[i][j] = 1
      @dist2[j][i] = 1
    end
  }
}
# WarshallFloyd
n.times{|i|
  n.times{|j|
    n.times{|k|
      @dist2[i][j] = @dist2[i][k] + @dist2[k][j] if (@dist2[i][j] > @dist2[i][k] + @dist2[k][j])
    }
  }
}
q = gets.to_i
q.times{
  s, t = gets.split.map(&:to_i)
  ans = @dist2[s-1][t-1]-1
  ans = -1 if ans > 300
  p ans
}
