#include <bits/stdc++.h>
#define inf (1<<29)
#define sq(n) ((n)*(n))
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define MEMSET(a) memset(a,0,sizeof(a))
using namespace std;

using ll=long long;
const int limit=100010;
using edge=struct{int to;ll cost;};
vector<edge> tree[limit];
ll depth[limit];

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;
	cin>>n;
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		tree[a].push_back({b,c});
		tree[b].push_back({a,c});
	}
	int q,k;
	cin>>q>>k;
	k--;
	dfs(k,-1,0);
	rep(i,q){
		int x,y;
		cin>>x>>y;
		x--;y--;
		cout<<depth[x]+depth[y]<<endl;
	}
	return 0;
}