#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

typedef long long ll;

const int maxn = 100000 + 10;

vector<ll> al[maxn];
ll dist[maxn], a[maxn], b[maxn], c[maxn];
bool vis[maxn];

struct node{
    ll n, d;
    node(): n(0), d(0){}
    node(ll tn, ll td): n(tn), d(td){}
};

struct cmp{
    bool operator ()(const ll &l1, const ll &l2){
        return dist[l1] > dist[l2];
    }
};

int main(){
    ll N, Q, K;
    memset(vis, 0, sizeof vis);
    scanf("%lld", &N);
    for (ll i = 1; i < N; ++i){
        scanf("%lld%lld%lld", &a[i], &b[i], &c[i]);
        al[a[i]].push_back(i);
        al[b[i]].push_back(i);
    }
    scanf("%lld%lld", &Q, &K);
    priority_queue<ll, vector<ll>, cmp> q;
    dist[K] = 0;
    vis[K] = true;
    q.push(K);
    ll cur, t;
    while (!q.empty()){
        cur = q.top();
        q.pop();
        for (ll i = 0; i < al[cur].size(); ++i){
            t = a[al[cur][i]];
            if (t == cur){
                t = b[al[cur][i]];
            }
            if (!vis[t]){
                vis[t] = true;
                dist[t] = dist[cur] + c[al[cur][i]];
                q.push(t);
            }
        }
    }
    ll x, y;
    for (ll i = 0; i < Q; ++i){
        scanf("%lld%lld", &x, &y);
        printf("%lld\n", dist[x] + dist[y]);
    }
 //   system("pause");
    return 0;
}