module M = Set.Make(struct type t = int * int let compare = compare end)
let inf = 1010101010101010

let () =
  Scanf.scanf "%d" @@ fun n ->
  let g = Array.init (n+1) (fun _ -> []) in
  for _ = 1 to n-1 do
    Scanf.scanf " %d %d %d" @@ fun a b c ->
    g.(a) <- (b, c) :: g.(a);
    g.(b) <- (a, c) :: g.(b);
  done;

  Scanf.scanf " %d %d" @@ fun q k ->

  let dist = Array.make (n+1) inf in
  dist.(k) <- 0;

  let rec loop pqi =
    if M.is_empty pqi then () else
    let (d, u) = M.min_elt pqi in
    let pqi' = M.remove (d,u) pqi in

    if d > dist.(u) then loop pqi' else
      g.(u) |> List.fold_left (fun pq (v, c) ->
        if d+c < dist.(v) then begin
          dist.(v) <- d+c;
          M.add (d+c, v) pq
        end else pq) pqi'
    |> loop
  in loop (M.singleton (0, k));

  for _ = 1 to q do
    Scanf.scanf " %d %d" @@ fun x y ->
    dist.(x) + dist.(y) |> Printf.printf "%d\n"
  done