#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
#define INF 1e18
const int maxn = 1e5 + 10;
struct road{
	int v;
	int to;
	int next;
}r[maxn];
long long dis[maxn];
int head[maxn],cnt;
bool vis[maxn];
void inti(){
	memset(head, -1, sizeof(head));
	for(int i = 0; i < maxn; ++i){
		dis[i] = INF;
	}
	memset(vis, false, sizeof(vis));
	cnt = 0;
}
void build(long long s, long long e, long long w){
	r[cnt].v = w;
	r[cnt].to = e;
	r[cnt].next = head[s];
	head[s] = cnt++;
}
void spfa(long long s){
	queue<int>q;
	int end, i, top;
	q.push(s);
	vis[s] = true;
	dis[s] = 0;
	while(!q.empty()){
		top = q.front();
		q.pop();
		vis[top] = false;
		for(i = head[top]; i != -1; i = r[i].next){
			end = r[i].to;
			if(dis[end] > dis[top] + r[i].v){
				dis[end] = dis[top] + r[i].v;
				if(!vis[end]){
					q.push(end);
					vis[end] = true;
				}
			}
		}
	}
}
int main()
{
	long long n, s, e, w, q, k, i, a, b;
	scanf("%lld",&n);
	inti();
	for(i = 1; i < n; ++i){
		scanf("%lld %lld %lld", &s, &e, &w);
		build(s, e, w);
		build(e, s, w);
	}
	scanf("%lld %lld", &q, &k);
	spfa(k);
	for(i = 1; i <= q; ++i){
		scanf("%lld %lld", &a, &b);
		//cout << dis[a] << endl;
		printf("%lld\n",dis[a] + dis[b]);
	}
}