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

class Graph
{
  public:
    struct Edge
    {
        long long to;
        long long distance;
        bool operator<(const Edge &e)
        {
            return distance < e.distance;
        }

        bool operator>(const Edge &e)
        {
            return distance > e.distance;
        }
    };
    vector<vector<long long>> adjacency_matrix;
    long long node;
    vector<list<Edge>> edge;

    Graph(long long N)
    {
        node = N + 1;
        initializeEdgeList();
    }

    void initializeAdjacencyMatrix(long long init)
    {
        adjacency_matrix = vector<vector<long long>>(node, vector<long long>(node, init));
    }

    void initializeEdgeList()
    {
        edge = vector<list<Edge>>(node);
    }

    void updateAdjacencyMatrix(long long from, long long to, long long distance)
    {
        adjacency_matrix[from][to] = distance;
    }

    void addEdge(long long from, long long to, long long distance)
    {
        edge[from].push_back({to, distance});
    }

    // O(V^3)
    // CAUTION: Use adjacency matrix
    void runFloydWarshall()
    {
        for (int i = 0; i < node; i++)
        {
            for (int j = 0; j < node; j++)
            {
                for (int k = 0; k < node; k++)
                {
                    adjacency_matrix[j][k] = min(
                        adjacency_matrix[j][k], adjacency_matrix[j][i] + adjacency_matrix[i][k]);
                }
            }
        }
    }

    // O(VE)
    void runBellmanFord(long long from) {}

    // O(E + VlogV)
    // CAUTION: Use edge list
    vector<long long> runDijkstra(long long from, long long init)
    {
        vector<list<Edge>> edge_copy = edge;
        vector<long long> distance(node, init);
        distance[from] = 0;

        priority_queue<pair<long long, long long>> queue;
        for (auto itr = edge_copy[from].begin(); itr != edge_copy[from].end(); itr++)
        {
            queue.push(make_pair(itr->distance, itr->to));
            edge_copy[from].erase(itr);
            itr--;
        }

        while (!queue.empty())
        {
            long long d = queue.top().first;
            long long to = queue.top().second;
            queue.pop();
            if (distance[to] == init)
            {
                distance[to] = d;
                for (auto itr = edge_copy[to].begin(); itr != edge_copy[to].end(); itr++)
                {
                    if (distance[itr->to] == init)
                    {
                        queue.push(make_pair(itr->distance + d, itr->to));
                        edge_copy[to].erase(itr);
                        itr--;
                    }
                }
            }
        }

        return distance;
    }
};

int main()
{
    int N;
    cin >> N;

    Graph g = Graph(N);
    int a, b, c;
    for (int i = 0; i < N - 1; i++)
    {
        cin >> a >> b >> c;
        g.addEdge(a, b, c);
        g.addEdge(b, a, c);
    }

    int Q, K;
    cin >> Q >> K;

    int x, y;
    vector<long long> distance = g.runDijkstra(K, -1);
    for (int i = 0; i < Q; i++)
    {
        cin >> x >> y;
        cout << distance[x] + distance[y] << endl;
    }
}


Measured memory_bytes: 24440