#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll INF = 1e18;
int MOD = 1e9+7;
using edge = struct {int to; ll cost;};
vector<edge> tree[100010];
ll depth[100010];
void dfs(int v,int p,ll d){
    depth[v] = d;
    for(auto &e:tree[v]){
        if(e.to == p)continue;//行き先と来た道が一致してたら
        dfs(e.to,v,d+e.cost);
    }
}
int main(){
    int N,Q,K;
    cin >> N;
    for(int i = 0;i < N-1;i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--,b--;
        tree[a].push_back({b,c});
        tree[b].push_back({a,c});
    }
    cin >> Q >> K;
    dfs(K-1,-1,0);
    for(int i = 0;i < Q;i++){
        int a,b;
        cin >> a >> b;
        cout << depth[a-1] + depth[b-1] << endl;
    }
}