
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec for_iter a b f = if a >= b then [] else let x = f a in x :: for_iter (a+1) b f
let rec for_iter_ a b f = if a >= b then () else (f a; for_iter_ (a+1) b f)

let list_of_string str = range 0 (String.length str) |> List.map (fun i -> str.[i])
let array_of_string str = Array.init (String.length str) (fun i -> str.[i])

let inf = 20202020202020

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

let () =
  let n = read_int () in
  let degs = Array.make (n+1) 0 in
  let edges = for_iter 0 (n-1) (fun _ ->
    let a = read_int () in let b = read_int () in let c = read_int () in
    degs.(a) <- degs.(a) + 1; degs.(b) <- degs.(b) + 1;
    (a, b, c)) in

  let n = n+1 in

  let graph = Array.init n (fun i -> Array.make degs.(i) (-1, -1)) in
  for_iter_ 0 n (fun i -> degs.(i) <- 0);
  List.iter (fun (a, b, c) ->
    graph.(a).(degs.(a)) <- (b, c); degs.(a) <- degs.(a) + 1;
    graph.(b).(degs.(b)) <- (a, c); degs.(b) <- degs.(b) + 1) edges;

  let q = read_int () in let k = read_int () in

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