#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 100005
#define ll long long
struct Edge{
    ll to;
    ll next;
    ll cost;
};
Edge edge[MAX*2];
ll head[MAX];
ll dis[MAX];
ll n,u,v,w,q,k,cnt;
void DFS(ll u,ll v,ll w)
{
    dis[u]=w;
    for(ll i=head[u];i!=-1;i=edge[i].next)
    {
        ll to=edge[i].to;
        if(to==v)
            continue;
        DFS(to,u,w+edge[i].cost);
    }
    return ;
}
int main()
{
    scanf("%lld",&n);
    memset(head,-1,sizeof(head));
    for(ll i=1;i<=n-1;i++)
    {
        scanf("%lld%lld%lld",&u,&v,&w);
        edge[cnt].to=v;
        edge[cnt].cost=w;
        edge[cnt].next=head[u];
        head[u]=cnt++;
        edge[cnt].to=u;
        edge[cnt].cost=w;
        edge[cnt].next=head[v];
        head[v]=cnt++;
    }
    scanf("%lld%lld",&q,&k);
    DFS(k,-1,0);
    while(q--)
    {
        scanf("%lld%lld",&u,&v);
        printf("%lld\n",dis[u]+dis[v]);
    }
    return 0;
}
