#include <cstdio>
#include <vector>
#define maxn 100010
using namespace std;

int n, u, v, c, q, k, xi, yi;
long long dis[maxn];
bool vis[maxn];
struct Edge {
	int u, v, c;
	Edge(int u, int v, int c): u(u), v(v), c(c) {}
};
vector<Edge> V[maxn];
void dfs(int x, long long d) {
	vis[x] = true;
	dis[x] = d;
	for (int i = 0; i < V[x].size(); i++) {
		int v = V[x][i].v, c = V[x][i].c;
		if (!vis[v])
			dfs(v, d + c);
	}
}
int main(void) {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		scanf("%d%d%d", &u, &v, &c);
		V[u].push_back(Edge(u, v, c));
		V[v].push_back(Edge(v, u, c));
	}
	scanf("%d%d", &q, &k);
	dfs(k, 0);
	for (int i = 0; i < q; i++) {
		scanf("%d%d", &xi, &yi);
		printf("%lld\n", dis[xi] + dis[yi]);
	}
}