#include <bits/stdc++.h>
using namespace std;

const int nm = 1e5;
int n, q, k;
long long d[nm];
vector<pair<int, int>> g[nm];

void dfs(int v, int p) {
	for (auto &e : g[v]) {
		if (e.first == p)
			continue;
		d[e.first] = d[v] + e.second;
		dfs(e.first, v);
	}
}

int main() {
	cin >> n;
	for (int i = 0, a, b, c; i < n - 1; i++) {
		cin >> a >> b >> c, a--, b--;
		g[a].emplace_back(b, c);
		g[b].emplace_back(a, c);
	}
	cin >> q >> k, k--;
	d[k] = 0, dfs(k, -1);
	for (int i = 0, x, y; i < q; i++) {
		cin >> x >> y, x--, y--;
		cout << d[x] + d[y] << endl;
	}

}
