#include <iostream> 
#include <cstring>
#include <queue>
using namespace std;
const int N = 1e5 + 7;
struct Edge {
	int to, nxt, w;
}e[N << 1];
long long dis[N];
int cur, head[N];
bool vis[N];
void init() {
	cur = 0;
	memset(head, -1, sizeof head);
	memset(dis, 0, sizeof dis);
	memset(vis, 0, sizeof vis);
}
void add(int u, int v, int w) {
	e[cur].to = v;
	e[cur].w = w;
	e[cur].nxt = head[u];
	head[u] = cur++;
}
void bfs(int rt) {
	dis[rt] = 0;
	vis[rt] = 1;
	queue<int> q;
	q.push(rt);
	while (!q.empty()) {
		rt = q.front(); q.pop();
		for (int i = head[rt]; ~i; i = e[i].nxt) {
			int v = e[i].to;
			if (!vis[v]) {
				vis[v] = 1;
				dis[v] = dis[rt] + e[i].w;
				q.push(v);
			}
		}
	}
}
int main()
{
	ios::sync_with_stdio(false);
	int n;
	while (cin >> n) {
		init();
		int u, v, w, q, k;
		for (int i = 1; i < n; ++i) {
			cin >> u >> v >> w;
			add(u, v, w);
			add(v, u, w);
		}
		cin >> q >> k;
		bfs(k);
		while (q--) {
			cin >> u >> v;
			cout << dis[u] + dis[v] << endl;
		}
	}

	return 0;
}