#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

struct Edge{
    int to, cost;
    Edge() = default;
    Edge(int to, int cost) : to(to), cost(cost) {}
};

template<typename T>
struct CostLCA{
    using G = vector<vector<Edge>>;

    const int ub_log;
    vector<int> depth;
    vector<T> costs;
    const G& g;
    vector<vector<int>> table;

    CostLCA(const G& g) : g(g), depth(g.size()), costs(g.size()), ub_log(32 - __builtin_clz(g.size())){
        table.assign(ub_log, vector<int>(g.size(), -1));
    }

    void dfs(int from, int par = -1, int dep = 0, T sum = 0){
        table[0][from] = par;
        depth[from] = dep;
        costs[from] = sum;
        for(int i = 0; i < g[from].size(); ++i){
            int to = g[from][i].to, cost = g[from][i].cost;
            if(to != par)   dfs(to, from, dep + 1, sum + cost);
        }
    }

    void build(int root = 0){
        dfs(root);
        for(int k = 0; k + 1 < ub_log; ++k){
            for(int i = 0; i < table[k].size(); ++i){
                if(table[k][i] == -1)   table[k + 1][i] = -1;
                else    table[k + 1][i] = table[k][table[k][i]];
            }
        }
    }

    int query(int u, int v){
        if(depth[u] > depth[v]) swap(u, v);

        for(int i = ub_log - 1; i >= 0; --i){
            if(((depth[v] - depth[u]) >> i) & 1)    v = table[i][v];
        }
        if(u == v)  return u;

        for(int i = ub_log - 1; i >= 0; --i){
            if(table[i][u] != table[i][v]){
                u = table[i][u];
                v = table[i][v];
            }
        }
        return table[0][u];
    }

    int length(int u, int v){
        int lca = query(u, v);
        return depth[u] + depth[v] - depth[lca] * 2;
    }

    T dist(int u, int v){
        int lca = query(u, v);
        return costs[u] + costs[v] - costs[lca] * 2;
    }

    void print(){
        for(int k = 0; k + 1 < ub_log; ++k){
            for(int i = 0; i < table[k].size(); ++i){
                cerr << table[k][i] << " ";
            }
            cerr << "\n";
        }
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<vector<Edge>> graph(n);
    for(int i = 0; i < n - 1; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        graph[a].push_back(Edge(b, c));
        graph[b].push_back(Edge(a, c));
    }
    CostLCA<ll> data(graph);
    data.build();
    int q, k;
    cin >> q >> k;
    --k;
    for(int i = 0; i < q; ++i){
        int x, y;
        cin >> x >> y;
        --x, --y;
        ll ans = data.dist(x, k) + data.dist(y, k);
        cout << ans << "\n";
    }
}

Measured memory_bytes: 18808