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

struct edge {
	int to;
	ll cost;
};

int n;
vector<edge> g[100001];
ll dist[100001];

void dfs(int x,int p, ll count){
    dist[x] = count;
    for(auto e : g[x]){
        if(e.to!=p){
            dfs(e.to,x,count+e.cost);
        }
    }
}

int main(){
 cin>>n;

 for(int i=0;i<n-1;i++){
     int a,b,c;
     cin>>a>>b>>c;
     g[a].push_back({b,c});
     g[b].push_back({a,c});
 }
 int q,k;
 cin>>q>>k;

 dfs(k,-1,0);

 for(int i=0;i<q;i++){
 	int x,y;
 	cin>>x>>y;
 	cout<<dist[x]+dist[y]<<endl;
 }

}
