#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int, ll> pil;
typedef vector<pil> vpil;

vector<vpil> adj;
vector<ll> d;

void dfs(int x) {
	for(auto e:adj[x]) if(d[e.first]==-1) {
		d[e.first]=d[x]+e.second;
		dfs(e.first);
	}
}

int main() {
	int i, k, q, n, u, v;
	ll w;
	scanf("%d", &n);
	adj.assign(n+1, vpil(0));
	for(i=0; i<n-1; i++) {
		scanf("%d%d%lld", &u, &v, &w);
		adj[u].push_back(pil(v, w));
		adj[v].push_back(pil(u, w));
	}
	d.assign(n+1, -1);
	scanf("%d%d", &q, &k);
	d[k]=0;
	dfs(k);
	for(; q; q--) {
		scanf("%d%d", &u, &v);
		printf("%lld\n", d[u]+d[v]);
	}
	return 0;
}