#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
long long n,q,k,x,y,z,dist[111111];
vector<pair<long long,long long> > g[111111];
void dfs(long long i,long long fa)
{
	for (long long j=0;j<g[i].size();j++)
	{
		long long to=g[i][j].first,val=g[i][j].second;
		if (to==fa) continue;
		dist[to]=dist[i]+val;
		dfs(to,i);
	}
}
int main()
{
	scanf("%lld",&n);
	for (long long i=1;i<n;i++)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		g[x].push_back(make_pair(y,z));
		g[y].push_back(make_pair(x,z));  
	}
	scanf("%lld%lld",&q,&k);
	dfs(k,0);
	while(q--)
	{
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",dist[x]+dist[y]);
	}
	return 0;
}