import java.io._
import java.util.StringTokenizer

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N = in.next().toInt
  // (node, cost)
  val graph: Array[List[(Int, Int)]] = Array.fill(N+1)(Nil)
  for(_ <- 1 to N-1) {
    val a, b, cost = in.next().toInt
    graph(a) = (b, cost) :: graph(a)
    graph(b) = (a, cost) :: graph(b)
  }

  val Q, K = in.next().toInt

  // dfs
  val stack = new scala.collection.mutable.Stack[(Int, Long)] // (nowNode, cost)
  stack.push((K, 0))

  val dp = new Array[Long](N+1)
  dp(K) = 2

  while (!stack.isEmpty) {
    val (now, accCost) = stack.pop
    for((node, cost) <- graph(now)) {
      if(dp(node) == 0) {
        dp(node) = accCost + cost
        stack.push((node, accCost + cost))
      }
    }
  }

  for (_ <- 1 to Q) {
    val x, y = in.next().toInt
    val ans: Long = dp(x) + dp(y)
    pw.println(ans)
  }
  pw.flush()

}


class InputReader(stream: InputStream) {
  private val reader = new BufferedReader(new InputStreamReader(stream))
  private var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
