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

int main() {
	int n, q, k;
	cin >> n;
	vector<vector<pair<int, int>>> v(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		v[a].push_back(make_pair(b, c));
		v[b].push_back(make_pair(a, c));
	}
	cin >> q >> k;
	vector<int64_t> d(n, -1);
	stack<int> s;
	d[k - 1] = 0;
	s.push(k - 1);
	while (!s.empty()) {
		int i = s.top();
		s.pop();
		for (auto it = begin(v[i]); it != end(v[i]); it++) {
			if (d[it->first] == -1) {
				d[it->first] = d[i] + it->second;
				s.push(it->first);
			}
		}
	}
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		cout << d[x] + d[y] << endl;
	}
	return 0;
}
