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;
}

long[][] calc(int n, int[][] adj) {
    auto d = new long[][](n, n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = adj[i][j] == 0 ? 1_000_000_000_000L : adj[i][j];
        }
    }

    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (d[i][j] > d[i][k] + d[k][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }
    return d;
}

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

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

    auto d = calc(n, adj);

    auto qk = readints();
    int q = qk[0], k = qk[1];
    for (int i = 0; i < q; i++) {
        auto xy = readints();
        int x = xy[0] - 1, y = xy[1] - 1;

        auto ans = d[x][k - 1] + d[k - 1][y];
        writeln(ans);
    }
}
