#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

using namespace std;

class LowestCommonAncestor {

public:
    vector<vector<int>> graph;
    int log_v;
    vector<vector<int>> parent;
    vector<int> depth;

    // graph[ノード番号] = リンク先のノード番号のリスト (e.g. graph[0] = [1, 2, 3])
    LowestCommonAncestor(const vector<vector<int>> &graph) :graph(graph) {
        int v = graph.size();
        this->log_v = int(log2(v)) + 1;
        parent = std::vector<vector<int>>(log_v, vector<int>(v));
        depth = vector<int>(v);
    }

    void init(int root) {
        dfs(root, -1, 0);

        for (int k = 0; k + 1 < this->log_v; k++) {
            for (int v = 0; v < this->graph.size(); v++) {
                if (parent[k][v] < 0) {
                    parent[k + 1][v] = -1;
                }
                else {
                    parent[k + 1][v] = parent[k][parent[k][v]];
                }
            }
        }
    }

    // uとvの共通祖先
    int lca(int u, int v) {
        if (depth[u] > depth[v]) {
            swap(u, v);
        }
        for (int k = 0; k < this->log_v; ++k) {
            if ((depth[v] - depth[u]) >> k & 1) {
                v = parent[k][v];
            }

        }
        if (u == v) {
            return u;
        }

        for (int k = this->log_v - 1; k >= 0; --k) {
            if (parent[k][u] != parent[k][v]) {
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];
    }

private:
    void dfs(int v, int p, int d) {
        parent[0][v] = p;
        depth[v] = d;
        for (int i = 0; i < graph[v].size(); ++i) {
            if (graph[v][i] != p) {
                dfs(graph[v][i], v, d + 1);
            }
        }
    }
};

void dfs(int v, int parent, vector<LL> &dist, const map<int, vector<pair<int, LL>>> &e) {
    LL now = dist[v];
    FOE(p, e.at(v)) {
        if (p.first != parent) {
            dist[p.first] = now + p.second;
            dfs(p.first, v, dist, e);
        }
    }
}

vector<LL> distance(int num, int root, const map<int, vector<pair<int, LL>>> &e) {
    vector<LL> dist(num, INT_MAX);
    dist[root] = 0;
    dfs(0, -1, dist, e);
    return dist;
}

int main(int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N, a, b, c;
    cin >> N;
    map<int, vector<pair<int, LL>>> e;
    vector<vector<int>> graph(N);
    FOR(_, 0, N - 1) {
        cin >> a >> b >> c;
        a--; b--;
        e[a].push_back({b, c});
        e[b].push_back({a, c});
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    LowestCommonAncestor lca = LowestCommonAncestor(graph);
    lca.init(0);

    vector<LL> dist = distance(N, 0, e);
    int Q, K, x, y;
    cin >> Q >> K;
    K--;
    FOR(i, 0, Q) {
        cin >> x >> y;
        x--; y--;
        LL a = dist[x] + dist[K] - 2 * dist[lca.lca(x, K)];
        LL b = dist[y] + dist[K] - 2 * dist[lca.lca(y, K)];
        cout << a + b << endl;
    }

    return 0;
}

Measured memory_bytes: 40952