use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};


fn solve(
    n: usize,
    abc: Vec<(usize, usize, usize)>,
    xy: Vec<(usize, usize)>,
    k: usize,
) -> Vec<usize> {
    let mut branches = vec![vec![]; n];
    for (a, b, c) in abc.into_iter() {
        branches[a - 1].push((b - 1, c));
        branches[b - 1].push((a - 1, c));
    }

    fn calc_dist_from_k(branches: Vec<Vec<(usize, usize)>>, k: usize, n: usize) -> Vec<usize> {
        let mut dist_from_k = vec![None; n];
        dist_from_k[k] = Some(0);
        let mut ps = vec![k];
        loop {
            let mut next_ps = vec![];
            for &p in &ps {
                let current_dist = dist_from_k[p].expect("A");
                for &(next_p, dist) in &branches[p] {
                    if dist_from_k[next_p].is_none() {
                        next_ps.push(next_p);
                        dist_from_k[next_p] = Some(current_dist + dist);
                    }
                }
            }
            if next_ps.is_empty() {
                break;
            }
            ps = next_ps;
        }
        dist_from_k
            .into_iter()
            .map(|o| o.expect("not all"))
            .collect()
    }

    let dist_from_k = calc_dist_from_k(branches, k - 1, n);
    xy.into_iter()
        .map(|(x, y)| dist_from_k[x - 1] + dist_from_k[y - 1])
        .collect()
}


fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    let n = sc.next::<usize>();
    let abc = sc.trios(n - 1);
    let (q, k) = (sc.next(), sc.next());
    let xy = sc.pairs(q);
    for l in solve(n, abc, xy, k) {
        println!("{}", l);
    }
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
    where
        <T as FromStr>::Err: Debug,
    {
        self.buf.clear();
        for c in self.bytes
            .by_ref()
            .map(|c| c.unwrap())
            .skip_while(|&c| c == ' ' as u8 || c == '\n' as u8)
            .take_while(|&c| !(c == ' ' as u8 || c == '\n' as u8))
        {
            self.buf.push(c);
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
    where
        <A as FromStr>::Err: Debug,
        <B as FromStr>::Err: Debug,
        <C as FromStr>::Err: Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        <T as FromStr>::Err: Debug,
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_foreach<T: Display>(answer: &[T]) {
    for x in answer {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_yn(answer: bool, yes: &str, no: &str) {
    println!("{}", if answer { yes } else { no });
}


#[allow(dead_code)]
fn print_or<T: Display>(answer: &Option<T>, or: &T) {
    match *answer {
        Some(ref x) => println!("{}", x),
        None => println!("{}", or),
    }
}


Measured memory_bytes: 22780