#include <bits/stdc++.h>
using namespace std;

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;
struct Graph {
    struct Edge {
        int from;
        int to;
        lint cost;
        int index;
        int color;
    };
    struct Node {
        int index;
        bool check;
        int color;
        lint dist;
        std::vector<Edge> edges;
        Node() {
            index = -1;
            check = false;
            color = -1;
            dist  = INF;
            std::vector<Edge>(0);
        }
    };

    int numNodes;
    int numColor;
    bool directed;
    std::vector<Node> nodes;
    std::vector<Edge> edges;

    Graph(int N) : numNodes(N), nodes(N) {
        for (int i = 0; i < N; i++)
            nodes[i].index = i;
        numColor = -1;
        directed = false;
    }
    Graph(int N, bool directed) : numNodes(N), nodes(N) {
        for (int i = 0; i < N; i++)
            nodes[i].index = i;
        numColor = -1;
        directed = true;
    }

    void addEdge(int from, int to, int cost) {
        nodes[from].edges.push_back(Edge({from, to, cost}));
        if (!directed) nodes[to].edges.push_back(Edge({to, from, cost}));
    }

    void addEdge(int from, int to) {
        nodes[from].edges.push_back(Edge({from, to}));
        if (!directed) nodes[to].edges.push_back(Edge({to, from}));
    }

    void bfs(int startIndex) {
        for (auto& node : nodes)
            node.dist = INF;
        nodes[startIndex].dist = 0;
        std::queue<int> que({startIndex});
        while (!que.empty()) {
            int currentIndex = que.front();
            que.pop();
            for (auto edge : nodes[currentIndex].edges) {
                if (nodes[edge.to].dist == INF) {
                    nodes[edge.to].dist = nodes[currentIndex].dist + edge.cost;
                    que.push(edge.to);
                }
            }
        }
    }

    void coloring() {
        int c = 0;
        for (auto& node : nodes) {
            if (node.color != -1) continue;
            node.color = c;
            std::queue<int> que({node.index});
            while (!que.empty()) {
                int currentIndex = que.front();
                for (auto edge : nodes[currentIndex].edges) {
                    if (nodes[edge.to].color != -1) continue;
                    nodes[edge.to].color = c;
                    que.push(nodes[edge.to].index);
                }
            }
            c++;
        }
        numColor = c;
    }
};
int main() {
    int N;
    cin >> N;
    Graph g(N);
    rep(_, N - 1) {
        int a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        g.addEdge(a, b, c);
    }
    int Q, K;
    cin >> Q >> K;
    K--;
    g.bfs(K);

    rep(_, Q) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        cout << g.nodes[a].dist + g.nodes[b].dist << endl;
    }
    return 0;
}

Measured memory_bytes: 13056