let n = read_int ()
let g = Array.make n []
let ds = Array.make n 0
let rec f v p d = ds.(v) <- d; List.iter (fun (u, c) -> if u <> p then f u v (d + c)) g.(v)
let _ = for _ = 1 to n - 1 do Scanf.scanf " %d %d %d" @@ fun a b c -> g.(a - 1) <- (b - 1, c) :: g.(a - 1); g.(b - 1) <- (a - 1, c) :: g.(b - 1) done
let q, k = Scanf.scanf " %d %d" @@ fun a b -> a, b - 1
let _ = f k ~-1 0; for _ = 1 to q do Scanf.scanf " %d %d" @@ fun x y -> Printf.printf "%d\n" @@ ds.(x - 1) + ds.(y - 1) done