import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.stdio;
import std.string;
import std.range;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

struct S {
    int node;
    long cost;
}

long[] bfs(int k, int n, S[][int] adj) {
    auto cost = new long[n + 1];
    auto used = new bool[n + 1];

    S[] q = [S(k, 0)];
    while (q.length > 0) {
        auto d = q[0];
        q = q[1 .. $];

        if (used[d.node])
            continue;
        used[d.node] = true;
        cost[d.node] = d.cost;

        if (d.node !in adj)
            continue;
        foreach (s; adj[d.node]) {
            q ~= S(s.node, d.cost + s.cost);
        }
    }
    return cost;
}

void main() {
    int n = readint();

    S[][int] adj;
    for (int i = 0; i < n - 1; i++) {
        auto abc = readints();
        int a = abc[0], b = abc[1], c = abc[2];
        adj[a] ~= S(b, c);
        adj[b] ~= S(a, c);
    }

    auto qk = readints();
    int q = qk[0], k = qk[1];

    auto cost = bfs(k, n, adj);
    for (int i = 0; i < q; i++) {
        auto xy = readints();
        int x = xy[0], y = xy[1];

        auto ans = cost[x] + cost[y];
        writeln(ans);
    }
}
