#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef pair<int,int>P;
typedef long long ll;

vector<P>E[100000];
ll d[100000];
void dfs(int v,int p){
	for(P u:E[v]){
		if(u.second!=p){
			d[u.second]=d[v]+u.first;dfs(u.second,v);
		}
	}
}
int main(){
	int n;scanf("%d",&n);
	rep(i,n-1){
		int a,b,c;scanf("%d%d%d",&a,&b,&c);a--;b--;
		E[a].push_back(P(c,b));E[b].push_back(P(c,a));
	}
	int q,k;scanf("%d%d",&q,&k);k--;
	dfs(k,-1);
	rep(i,q){
		int x,y;scanf("%d%d",&x,&y);x--;y--;
		printf("%lld\n",d[x]+d[y]);
	}
}