import scala.collection.mutable.Stack

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val e = List.fill(n-1)((sc.nextInt()-1, sc.nextInt()-1, sc.nextLong()))
  val adj = Array.fill(n)(List[(Int, Long)]())
  for ((a, b, c) <- e) {
    adj(a) ::= (b, c)
    adj(b) ::= (a, c)
  }
  val q = sc.nextInt()
  val k = sc.nextInt()-1
  val xy = List.fill(q)((sc.nextInt()-1, sc.nextInt()-1))

  val d = Array.fill(n)(-1L)
  d(k) = 0
  val stack = Stack(k)
  while (stack.nonEmpty) {
    val u = stack.pop()
    for ((v, c) <- adj(u) if d(v) == -1) {
      stack.push(v)
      d(v) = d(u) + c
    }
  }

  val pw = new java.io.PrintWriter(Console.out)
  for ((x, y) <- xy) {
    pw.println(d(x) + d(y))
  }
  pw.flush()
}
