open Scanf

let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let min_dists num start graph =
  let res = Array.make num (-1) in
  let rec trav v p d =
    res.(v) <- d;
    List.iter (fun (w, c) -> if w <> p then trav w v (d + c)) graph.(v) in
  trav start (-1) 0;
  res

let () =
  let n = scanf "%d" (fun i -> i) in
  let edges = Array.init (n-1) (fun _ -> scanf " %d %d %d" (fun a b c -> a, b, c)) in
  let graph = Array.init (n+1) (fun _ -> []) in
  Array.iter (fun (a, b, c) ->
    graph.(a) <- (b, c) :: graph.(a);
    graph.(b) <- (a, c) :: graph.(b)) edges;

  let q, k = scanf " %d %d" (fun q k -> q, k) in
  let dists = min_dists (n+1) k graph in
  for_iter_ 0 q (fun _ ->
    let x, y = scanf " %d %d" (fun x y -> x, y) in
    Printf.printf "%d\n" (dists.(x) + dists.(y)))
