#include <bits/stdc++.h>
using namespace std;
#define maxn 100010
vector<int> w[maxn];
long long d[maxn];
int a[maxn], b[maxn], c[maxn];
void work(int x, int p) {
	for (int i = 0; i < w[x].size(); i++) {
		int u = w[x][i];
		if (a[u] == p || b[u] == p) continue;
		if (a[u] == x) {
			d[b[u]] = d[x] + c[u];
			work(b[u], x);
		} else {
			d[a[u]] = d[x] + c[u];
			work(a[u], x);
		}
	}
} 
int main()
{
	int n, q, k, x, y;
	
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);
		w[a[i]].push_back(i);
		w[b[i]].push_back(i);
	}
	scanf("%d%d", &q, &k);
	d[k] = 0;
	work(k, 0);
	while (q--) {
		scanf("%d%d", &x, &y);
		printf("%lld\n", d[x] + d[y]);
	}
} 