#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream>
using namespace  std;  
#define  ll long long  
static const ll INF=1e9;
static const ll MAX=1e5+7;
const    ll   len=1e5+5;
ll n;
ll m[len][len],d[len];
void dkstl(ll s)
{
	ll u,minm;
	ll flag[len];
	for(ll i=0;i<n;++i)
	{
		d[i]=INF;
		flag[i]=0;
	}
	d[s]=0;
	while(1)
	{
		minm=INF;u=-1;
		for(ll i=0;i<n;++i)
		{
			if(flag[i]==0&&d[i]<minm)
			{
				u=i;
				minm=d[i];
			}
		}
		if(u==-1)break;
		flag[u]=1;
		for(ll v=0;v<n;++v)
		{
			if(flag[v]==0&&m[u][v]!=INF)
			{
				if(d[v]>m[u][v]+d[u])
					d[v]=m[u][v]+d[u];
			}
		}
	}
	//for(ll i=0;i<n;++i)
	//	printf("%lld ",d[i]);
	//return d[z];
}
int main()
{	
	while(cin>>n)
	{
		ll i,j,t;
		for(i=0;i<n;++i)
		{
			for(j=0;j<n;++j)
				m[i][j]=INF;
		}
		for(ll u=0;u<n-1;++u)
		{
			scanf("%lld%lld",&i,&j);
			i--;j--;
			cin>>t;
			m[i][j]=t;
			m[j][i]=t;
		}
		//for(i=0;i<n;++i)
		{
			//for(j=0;j<n;++j)
				//cout<<m[i][j]<<' ';
		//	cout<<endl;
		}
		ll q,k;
		cin>>q>>k;
		dkstl(k);
		for(ll v=1;v<=q;++v)
		{
			scanf("%lld%lld",&i,&j);
			i--;j--;
			printf("%lld\n",d[i]+d[j]);
		}
	}
	return 0;
}