#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(dead_code)]
#![allow(unused_variables)]

use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
use std::mem::swap;
use std::io::prelude::*; // input()

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[derive(Clone)]
struct Edge {
    to: usize,
    cost: usize
}

// https://qiita.com/hatoo@github/items/fa14ad36a1b568d14f3e
// ↓
use std::collections::BinaryHeap;
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
// ↑
// https://qiita.com/hatoo@github/items/fa14ad36a1b568d14f3e

fn main() {
    input! {
        n: usize,
        abc: [(usize1, usize1, usize); n-1],
        q: usize,
        k: usize1,
        xy: [(usize1, usize1); q],
    }
    let mut g = vec![vec![]; n];
    for (a, b, c) in abc {
        g[a].push(Edge {to: b, cost: c});
        g[b].push(Edge {to: a, cost: c});
    }
    let dod = |a: usize| {
        let mut d = vec![usize::max_value(); n];
        d[a] = 0;
        let mut que = BinaryHeap::new();
        que.push(Rev((0, a)));
        while !que.is_empty() {
            let Rev((v_min_d, v)) = que.pop().unwrap();
            if d[v] < v_min_d {
                continue;
            }
            for e in &g[v] {
                if d[e.to] > d[v] + e.cost {
                    d[e.to] = d[v] + e.cost;
                    que.push(Rev((d[e.to], e.to)))
                }
            }
        }
        for (x, y) in xy {
            println!("{}", d[x] + d[y]);
        }
    };
    dod(k);
}


Measured memory_bytes: 27896