#include <cstdio>
#include <vector>
#define N 300005
using namespace std;
typedef long long ll;
ll n, q, k, c[N];
vector<ll> a[N], b[N];

void f(ll p, ll q, ll r) {
	c[p] = r;
	for(ll i=0; i<a[p].size(); i++)
		if(a[p][i]!=q) f(a[p][i], p, r+b[p][i]);
}

int main() {
	ll u, v, w;
	scanf("%lld", &n);
	while(--n) {
		scanf("%lld%lld%lld", &u, &v, &w);
		a[u].push_back(v);
		b[u].push_back(w);
		a[v].push_back(u);
		b[v].push_back(w);
	}
	scanf("%lld%lld", &q, &k);
	f(k, 0, 0);
	while(q--) {
		scanf("%lld%lld", &u, &v);
		printf("%lld\n", c[u]+c[v]);
	}
	return 0;
}