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

class HLD {
	vector<vector<int>> G;
	vector<int> vid, head, heavy, par, dep;
	int dfs(int v, int prev) {
		par[v] = prev;
		int cnt = 1, ma = 0;
		for (int to : G[v]) if (to != prev) {
			dep[to] = dep[v] + 1;
			int c = dfs(to, v);
			cnt += c;
			if (ma < c) {
				ma = c;
				heavy[v] = to;
			}
		}
		return cnt;
	}
public:
	HLD(int n) : G(n), vid(n, -1), head(n), heavy(n, -1), par(n), dep(n) {}
	void add(int u, int v) {
		G[u].push_back(v);
		G[v].push_back(u);
	}
	void build() {
		dfs(0, -1);
		int k = 0;
		queue<int> q;
		q.push(0);
		while (!q.empty()) {
			int h = q.front(); q.pop();
			for (int i = h; i != -1; i = heavy[i]) {
				vid[i] = k++;
				head[i] = h;
				for (int j : G[i]) if (j != par[i] && j != heavy[i]) q.push(j);
			}
		}
	}
	int operator[](int v) {
		return vid[v];
	}
	void for_each(int u, int v, function<void(int, int)> f) {
		while (true) {
			if (vid[u] > vid[v]) swap(u, v);
			f(max(vid[head[v]], vid[u]), vid[v]);
			if (head[u] == head[v]) break;
			v = par[head[v]];
		}
	}
	void for_each_directed(int u, int v, function<void(int, int, int)> f) {
		while (true) {
			if (vid[u] > vid[v]) {
				f(max(vid[head[u]], vid[v]), vid[u], 1);
				if (head[u] == head[v]) break;
				u = par[head[u]];
			}
			else {
				f(max(vid[head[v]], vid[u]), vid[v], 0);
				if (head[u] == head[v]) break;
				v = par[head[v]];
			}
		}
	}
	void for_each_edge(int u, int v, function<void(int, int)> f) {
		while (true) {
			if (vid[u] > vid[v]) swap(u, v);
			if (head[u] != head[v]) {
				f(vid[head[v]], vid[v]);
				v = par[head[v]];
			}
			else {
				if (u != v) f(vid[u] + 1, vid[v]);
				break;
			}
		}
	}
};

template <typename T>
class SegmentTree {
	using func_t = function<T(T, T)>;
	const int n;
	const T id;
	func_t merge;
	vector<T> data;
	int size(int n) {
		int res;
		for (res = 1; res < n; res <<= 1);
		return res;
	}
public:
	SegmentTree(int n_, T id_, func_t merge_) :
		n(size(n_)), id(id_), merge(merge_), data(n * 2, id) {}
	void Init(const vector<T>& data_) {
		for (int i = 0; i < (int)data_.size(); i++)
			data[i + n] = data_[i];
		for (int i = n - 1; i >= 0; i--)
			data[i] = merge(data[i * 2], data[i * 2 + 1]);
	}
	void Update(int p, T val) {
		p += n;
		data[p] = val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	void Add(int p, T val) {
		p += n;
		data[p] += val;
		while (p >>= 1) data[p] = merge(data[p * 2], data[p * 2 + 1]);
	}
	T Find(int i) {
		return data[i + n];
	}
	T Find(int l, int r) {
		l += n; r += n + 1;
		T res1 = id, res2 = id;
		while (l < r) {
			if (l & 1) res1 = merge(res1, data[l++]);
			if (r & 1) res2 = merge(data[--r], res2);
			l >>= 1; r >>= 1;
		}
		return merge(res1, res2);
	}
};

int main()
{
	ios::sync_with_stdio(false);
	int N, Q, K;
	cin >> N;
	HLD hld(N);
	vector<int> a(N - 1), b(N - 1), c(N - 1);
	for (int i = 0; i < N - 1; i++) {
		cin >> a[i] >> b[i] >> c[i]; a[i]--; b[i]--;
		hld.add(a[i], b[i]);
	}
	hld.build();
	SegmentTree<ll> st(N, 0, [](ll a, ll b) { return a + b; });
	for (int i = 0; i < N - 1; i++) {
		hld.for_each_edge(a[i], b[i], [&](int l, int r) {
			st.Add(l, c[i]);
		});
	}
	cin >> Q >> K; K--;
	for (int i = 0, x, y; i < Q; i++) {
		cin >> x >> y; x--; y--;
		ll res = 0;
		hld.for_each_edge(x, K, [&](int l, int r) {
			res += st.Find(l, r);
		});
		hld.for_each_edge(K, y, [&](int l, int r) {
			res += st.Find(l, r);
		});
		printf("%lld\n", res);
	}
	return 0;
}


Measured memory_bytes: 16512