#include<iostream>
#include<vector>

using namespace std;

int n,q,k,a,b,c,x,y;
typedef struct{int to;int cost;}edge;
edge e;

long long depth[100000];
vector<edge>g[100000];

void dfs(int current_v,int parent,long long cost){
    depth[current_v]=cost;
    for(auto x:g[current_v])if(x.to!=parent)dfs(x.to,current_v,cost+x.cost);//(木の子孫は全て未訪問)
    return;
}

int main(){
    cin>>n;
    for(int i=1;i<n;i++){cin>>a>>b>>c;g[a-1].push_back(edge{b-1,c});g[b-1].push_back(edge{a-1,c});}
    cin>>q>>k;
    dfs(--k,-1,0LL);
    for(int i=0;i<q;i++){
        cin>>x>>y;
        cout<<depth[x-1]+depth[y-1]<<endl;
    }
    return 0;
}