#include<bits/stdc++.h>
using namespace std;
#define ran 111111
int n,rt;
vector<pair<int,int > > e[ran];
long long int d[ran];
void dfs(int x,int fat){
	for(vector<pair<int,int> >::iterator it = e[x].begin(); it!=e[x].end(); it++){
		int y = it->first;
		if(y == fat)continue;
		d[y] = d[x] + it->second;
		dfs(y, x);
	}
}
int main(){
	int x,y,z,q;
	scanf("%d",&n);
	for(int i=1; i<n; i++){
		scanf("%d%d%d",&x,&y,&z);
		e[x].push_back(make_pair(y,z));
		e[y].push_back(make_pair(x,z));
	}
	scanf("%d%d",&q,&rt);
	dfs(rt,rt);
	while(q--){
		scanf("%d%d",&x,&y);
		cout << d[x] + d[y] << endl;
	}
	return 0;
}
