#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <queue>
#include <cmath>
using namespace std;
const long long INF = 1e9 * 10005;
const long long maxnum = 50005;
struct node{
	long long u, w;
	long long h;
}e[maxnum];
long long first[maxnum], Next[maxnum], n, m, Prev[maxnum], a, b;
long long dist[maxnum], d;
void spfa(long long v0)
{
	long long i;
	bool visited[maxnum];
	for(i = 1; i <= n; i++)
	{
		dist[i] = INF;
		visited[i] = false;
		/*cout << dist[i] << endl;*/
	}
	queue<long long>Q;
	Q.push(v0);
	visited[v0] = true;
	dist[v0] = 0;
	while(!Q.empty())
	{
		long long u = Q.front();
		Q.pop();
		visited[u] = false;
		long long k = first[u];
		while(k != -1)
		{
			long long v = e[k].w;
			long long val = e[k].h;
			if(dist[v] >= dist[u] + val)
			{
				if(dist[v] > dist[u] + val)
				{
					dist[v] = dist[u] + val;
					if(!visited[v])
					{
						Q.push(v);
						visited[v] = true;
					}
				}
			}
			k = Next[k];
		}
	}
}
int main()
{
	long long i, z;
		scanf("%lld", &n);
		memset(first, -1, sizeof(first));
		memset(Next, -1, sizeof(Next));
		z = 1;
		for(i = 1; i <= n - 1; i++)
		{
			scanf("%lld%lld%lld" , &a, &b, &d);

				Next[z] = first[a];
				first[a] = z;
				e[z].w = b;
				e[z].h = d;
				z++;
				Next[z] = first[b];
				first[b] = z;
				e[z].w = a;
				e[z].h = d;
				z++;
		}
		long long q, k;
		scanf("%lld%lld", &q, &k);
		while(q--)
		{
			scanf("%lld%lld", &a, &b);
			long long lenth = 0;
			spfa(a);
			lenth += dist[k];
			/*prlong longf("%d", lenth);*/
			spfa(k);
			lenth += dist[b];
			printf("%lld\n", lenth);
		}
	return 0;
}