#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<vector<int> > g;
vector<vector<int> > w;
vector<int> d;
void dfs(int s, int f, int we) {
	d[s] = we;
	for (int i = 0; i < g[s].size(); i++) {
		if (g[s][i] != f) {
			dfs(g[s][i], s, we + w[s][i]);
		}
	}
}
signed main() {
	int N;
	cin >> N;
	g.resize(N);
	w.resize(N);
	d.resize(N);
	int a, b, c;
	for (int i = 0; i < N - 1; i++) {
		cin >> a >> b >> c;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
		w[a].push_back(c);
		w[b].push_back(c);
	}
	int q, k;
	cin >> q >> k;
	k--;
	dfs(k, -1, 0);
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		a--;
		b--;
		cout << (d[a]+d[b]) << endl;
	}
	return 0;

}