import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
object Main extends App {

  val n = readInt()
  val nodes = Array.fill(n){Nil: List[Edge]}
  for (_ ← 1 until n) {
    val Array(a, b, c) = readLine.trim.split(' ').map(_.toInt)
    nodes(a - 1) ::= Edge(b - 1, c)
    nodes(b - 1) ::= Edge(a - 1, c)
  }
  val parents = Array.fill(n){ArrayBuffer[Int]()}
  val queue = mutable.Queue[Int](0)
  val depth = Array.fill(n){Int.MaxValue}
  depth(0) = 0
  val length = Array.fill(n){0L}
  while (queue.nonEmpty) {
    val current = queue.dequeue()
    for (Edge(to, cost) ← nodes(current) if depth(to) > depth(current)) {
      parents(to).append(current)
      while(parents(to).length <= parents(parents(to).last).length) {
        parents(to).append(parents(parents(to).last)(parents(to).length - 1))
      }
      depth(to) = depth(current) + 1
      length(to) = length(current) + cost
      queue.enqueue(to)
    }
  }
  val Array(q, k) = readLine.trim.split(' ').map(_.toInt)
  for (_ ← 0 until q) {
    val Array(x, y) = readLine.trim.split(' ').map(_.toInt - 1)
    val ca = mlca(x, k - 1)
    val cb = mlca(y, k - 1)
    println(length(x) + length(k - 1) * 2 + length(y) - length(ca) * 2 - length(cb) * 2)
  }

  def mlca(a: Int, b: Int): Int = {
    if (a == b) a
    else if (depth(a) == depth(b)){
      val first = findFirst(0, parents(a).length){i ⇒
        parents(a)(i) == parents(b)(i)
      }
      if (first == 0) parents(a).head
      else mlca(parents(a)(first - 1), parents(b)(first - 1))
    }else if (depth(a) > depth(b)) {
      val first = findFirst(0, parents(a).length){i ⇒
        depth(parents(a)(i)) <= depth(b)
      }
      if (first == 0) mlca(parents(a).head, b)
      else mlca(parents(a)(first - 1), b)
    }else {
      val first = findFirst(0, parents(b).length){i ⇒
        depth(parents(b)(i)) <= depth(a)
      }
      if (first == 0) mlca(a, parents(b).head)
      else mlca(a, parents(b)(first - 1))
    }
  }

  def findFirst(from: Int, until: Int)(@inline predicate: Int ⇒ Boolean): Int = {
    var left = from
    var right = until
    while(left < right){
      val mid = (left + right) / 2
      if (predicate(mid)) right = mid
      else left = mid + 1
    }
    right
  }

  case class Edge(to: Int, cost: Long)
}