module IntSet = Set.Make (struct
  type t = int
  let compare = compare
end)

let () =
  let n = Scanf.scanf "%d\n" (fun n -> n) in
  let abcs = Array.init (n - 1) (fun _ -> Scanf.scanf "%d %d %d\n" (fun a b c -> a, b, c)) in
  let q, k = Scanf.scanf "%d %d\n" (fun q k -> q, k) in
  let xys = Array.init q (fun _ -> Scanf.scanf "%d %d\n" (fun x y -> x, y)) in
  let es = Array.make n [] in
  Array.iter (fun (a, b, c) ->
    es.(a - 1) <- (b - 1, c) :: es.(a - 1);
    es.(b - 1) <- (a - 1, c) :: es.(b - 1)) abcs;
  let d = Array.make n 0 in
  let rec dfs vs v =
    List.fold_left (fun vs (u, c) ->
      if (IntSet.mem u vs)
      then vs
      else (d.(u) <- c + d.(v); dfs vs u)) (IntSet.add v vs) es.(v) in
  ignore (dfs IntSet.empty (k - 1));
  Array.iter (fun (x, y) ->
    Printf.printf "%d\n" (d.(x - 1) + d.(y - 1))) xys