let inf = 1 lsl 47

let n = read_int()
let m = n - 1

let vec = Array.make n []

let rec read_graph i =
  if i < m then (
    let u, v, w = Scanf.scanf " %d %d %d" (fun u v w -> u - 1, v - 1, w) in
    vec.(u) <- (v, w) :: vec.(u);
    vec.(v) <- (u, w) :: vec.(v);
    read_graph (i + 1)
  )

let shortest_path s =
  let d = Array.make n inf in
  d.(s) <- 0;
  let rec dfs = function
    [] -> ()
  | u :: stack ->
      let rec update stack = function
        [] -> stack
      | (v, w) :: rest ->
          if d.(v) < inf then update stack rest
          else (
            d.(v) <- d.(u) + w;
            update (v :: stack) rest
          ) in
      dfs (update stack vec.(u)) in
  dfs [s];
  d

let () =
  read_graph 0;
  let q, k = Scanf.scanf " %d %d" (fun q k -> q, k - 1) in
  let d = shortest_path k in
  let rec query i =
    if i < q then (
      let x, y = Scanf.scanf " %d %d" (fun x y -> x - 1, y - 1) in
      Printf.printf "%d\n" (d.(x) + d.(y));
      query (i + 1)
    ) in
  query 0
