#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, q, k;
vector<pair<ll, ll> > adj[100010];
bool done[100010];
ll dis[100010];
void find(ll a, ll d = 0)
{
	if (done[a]) return;
	done[a] = true;
	dis[a] = d;
	for (int i = 0; i < adj[a].size(); i++) find(adj[a][i].first, d+adj[a][i].second);

}
int main()
{
	scanf("%lld", &n);
	for (int i = 1; i < n; i++)
	{
		ll a, b, c;
		scanf("%lld%lld%lld", &a, &b, &c);
		adj[a].push_back(make_pair(b, c));
		adj[b].push_back(make_pair(a, c));
	}
	scanf("%lld%lld", &q, &k);
	find(k);
	for (int i = 0; i < q; i++)
	{
		ll a, b;
		scanf("%lld%lld", &a, &b);
		printf("%lld\n", dis[a]+dis[b]);
	}
}