#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;
        edge = vector<list<Edge>>(node);
    }

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

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

    // O(1)
    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;
    }

    // O(E)
    // CAUTION: Tree only
    vector<long long> runDFS(long long from, long long init)
    {
        vector<list<Edge>> edge_copy = edge;
        vector<long long> distance(node, init);
        distance[from] = 0;

        queue<long long> from_queue;
        queue<long long> to_queue;
        queue<long long> distance_queue;
        for (auto itr = edge_copy[from].begin(); itr != edge_copy[from].end(); itr++)
        {
            from_queue.push(from);
            to_queue.push(itr->to);
            distance_queue.push(itr->distance);
            edge_copy[from].erase(itr);
            itr--;
        }

        while (!from_queue.empty() && !to_queue.empty() && !distance_queue.empty())
        {
            from = from_queue.front();
            long long to = to_queue.front();
            long long d = distance_queue.front();
            from_queue.pop();
            to_queue.pop();
            distance_queue.pop();
            distance[to] = d;
            for (auto itr = edge_copy[to].begin(); itr != edge_copy[to].end(); itr++)
            {
                if (itr->to != from)
                {
                    from_queue.push(to);
                    to_queue.push(itr->to);
                    distance_queue.push(itr->distance + distance[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.runDFS(K, -1);
    for (int i = 0; i < Q; i++)
    {
        cin >> x >> y;
        cout << distance[x] + distance[y] << endl;
    }
}


Measured memory_bytes: 23040