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

struct root {
	int to;
	long long cost;
};

int N, Q, K;
vector<root> Root[100010];
static long long Dis[100010] = {};

void DFS(int v, int p, long long d) {
	Dis[v] = d;
	for (root x : Root[v]) {
		if (x.to == p) continue;
		DFS(x.to, v, d + x.cost);
	}
}

int main() {
	cin >> N;
	for (int i = 0; i < N - 1; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		Root[a].push_back(root{ b, c });
		Root[b].push_back(root{ a, c });
	}
	cin >> Q >> K;
	K--;
	DFS(K, -1, 0);
	for (int i = 0; i < Q; i++) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		cout << Dis[x] + Dis[y] << endl;
	}
}