// #includes {{{
#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define debug2(x) cerr << #x << " = [";REP(__ind,(x).size()){cerr << (x)[__ind] << ", ";}cerr << "] (L" << __LINE__ << ")" << endl;

const int INF=0x3f3f3f3f;

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

typedef pair<int,int> pii;

/*
#ifdef MYDEBUG
#include"debug.h"
#include"print.h"
#endif
*/
// }}}

//{{{ io
FILE *file_in=stdin,*file_out=stdout;
#define fin normal_in
#define fout normal_out
//const char fname[]="";
//FILE *fin=fopen(fname,"r"),*fout=fopen(fname,"w");
#ifdef __MINGW32__
#define LLD "%I64d"
#define LLU "%I64u"
#else
#define LLD "%lld"
#define LLU "%llu"
#endif
struct NORMAL_IN{
	bool cnt;
	NORMAL_IN():cnt(true){}
	operator int() const {return cnt;}
#define endl "\n"
	NORMAL_IN& operator>>(int &n){cnt=fscanf(file_in,"%d",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned int &n){cnt=fscanf(file_in,"%u",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long long &n){cnt=fscanf(file_in,LLD,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(unsigned long long &n){cnt=fscanf(file_in,LLU,&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(double &n){cnt=fscanf(file_in,"%lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(long double &n){cnt=fscanf(file_in,"%Lf",&n)!=EOF;return *this;}
	NORMAL_IN& operator>>(char *c){cnt=fscanf(file_in,"%s",c)!=EOF;return *this;}
	NORMAL_IN& operator>>(string &s){
		s.clear();
		for(bool r=false;;){
			const char c=getchar();
			if(c==EOF){ cnt=false; break;}
			const int t=isspace(c);
			if(!r and !t)r=true;
			if(r){
				if(!t)s.push_back(c);
				else break;
			}
		}
		return *this;
	}
	template<class T>
		NORMAL_IN& operator>>(vector<T> &v){
			int n;fscanf(file_in,"%d",&n);
			REP(i,n){
				T t;*this>>t;
				v.push_back(t);
			}
		}
} normal_in;

struct NORMAL_OUT{
	NORMAL_OUT& operator<<(const int &n){fprintf(file_out,"%d",n);return *this;}
	NORMAL_OUT& operator<<(const unsigned int &n){fprintf(file_out,"%u",n);return *this;}
	NORMAL_OUT& operator<<(const long long &n){fprintf(file_out,LLD,n);return *this;}
	NORMAL_OUT& operator<<(const unsigned long long &n){fprintf(file_out,LLU,n);return *this;}
	NORMAL_OUT& operator<<(const double &n){fprintf(file_out,"%lf",n);return *this;}
	NORMAL_OUT& operator<<(const long double &n){fprintf(file_out,"%Lf",n);return *this;}
	NORMAL_OUT& operator<<(const char c[]){fprintf(file_out,"%s",c);return *this;}
	NORMAL_OUT& operator<<(const string &s){fprintf(file_out,"%s",s.c_str());return *this;}
} normal_out;
//}}}

//{{{ Graph<Weight>
typedef int Node;
template<class Weight>
struct edge {
	int src, dst, rev;
	Weight weight;
	edge(int src, int dst, Weight weight=1,int rev=-1) :
		src(src), dst(dst), weight(weight), rev(rev){ }
};
template<class Weight>
bool operator < (const edge<Weight> &e, const edge<Weight> &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
		e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
//typedef vector<edge> edges;
//typedef vector<edges> Graph;
 
//typedef vector<Weight> Array;
//typedef vector<Array> Matrix;
 
template<class Weight>
struct graph:vector<vector<edge<Weight> > >{
	graph(){}
	graph(const int &n):vector<vector<edge<Weight> > >(n){}
	void _add_edge(int from, int to, Weight w, int rev=-1){
		if(this->size() < from + 1)this->resize(from + 1);
		this->at(from).push_back(edge<Weight>(from,to,w,rev));
	}
};
//add bi-directional edge
template<class Weight>
void addBiEdge(graph<Weight> &g, const pair<int,int> &e, Weight w=1){
	const int &from = e.first, &to = e.second;
	g._add_edge(from,to,w,g[to].size());
	g._add_edge(to,from,w,g[from].size()-1);
}
//add directional edge
template<class Weight>
void addEdge(graph<Weight> &g, const pair<int,int> &e, Weight w=1){
	const int &from = e.first, &to = e.second;
	g._add_edge(from,to,w);
}

typedef long long Weight;
typedef edge<Weight> Edge;
typedef graph<Weight> Graph;

#ifdef DEBUG
#include"graph/graphviz.h"
#endif
//}}}

//{{{ Union-Find
struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		int r;
		compress(x,r);
		return r;
	}
	int size(int x) {
		return -data[root(x)];
	}
	void compress(int x,int &r){
		if(data[x]<0){
			r=x;
			return;
		}
		compress(data[x],r);
		data[x]=r;
	}
};
//}}}

//{{{ void leastCommonAncestor(const Graph &g, int r, vector<Query> &qs) {
struct Query {
	int u, v, w;
	Query(int u, int v) : u(u), v(v), w(-1) { }
};
void visit(const Graph &g, int u, int w,
		unordered_map<int,unordered_map<int, int>> &qs, vector<int> &color,
		vector<int> &ancestor, UnionFind &uf) {
	ancestor[ uf.root(u) ] = u;
	FOR(e, g[u]) if (e->dst != w) {
		visit(g, e->dst, u, qs, color, ancestor, uf);
		uf.unionSet( e->src, e->dst );
		ancestor[ uf.root(u) ] = u;
	}
	color[u] = 1;
	for(auto &p:qs[u]) {
//		int w = (q->v == u ? q->u : q->u == u ? q->v : -1);
//		if (w >= 0 && color[w]) q->w = ancestor[ uf.root(w) ];
		int w = p.first;
		if(color[w]){
			p.second = ancestor[uf.root(w)];
		}
	}
}
void leastCommonAncestor(const Graph &g, int r, vector<Query> &qs) {
	unordered_map<int, unordered_map<int, int>> qm;
	for(auto &q:qs){
		qm[q.u][q.v] = -1;
		qm[q.v][q.u] = -1;
	}
	UnionFind uf(g.size());
	vector<int> color(g.size()), ancestor(g.size());
	visit(g, r, -1, qm, color, ancestor, uf);
	for(auto &q:qs){
		q.w = max(qm[q.u][q.v], qm[q.v][q.u]);
//		cerr<<"result: "<<q.u<<" "<<q.v<<" "<<qm[q.v][q.u]<<" "<<qm[q.u][q.v]<<endl;
	}
}
//}}}

vector<long long> dist;

//{{{ dfs
void dfs(const Graph &g, long long d = 0, int u=0, int p=-1){
	dist[u] = d;
	FOR(e,g[u]){
		if(e->dst==p)continue;
		dfs(g,d+e->weight,e->dst,u);
	}
}
//}}}

void solve(long long N, vector<long long> a, vector<long long> b, vector<long long> c, long long Q, long long K, vector<long long> x, vector<long long> y){
	graph<long long> g(N);
	dist.assign(N,-1);
	REP(i,a.size())addBiEdge(g,{a[i],b[i]},c[i]);
	dfs(g,0,K,-1);
	/*
	vector<Query> q;
	REP(i,Q){
		q.push_back(Query(x[i],y[i]));
	}
	leastCommonAncestor(g,K,q);
	*/
	REP(i,Q){
		fout<<dist[x[i]] + dist[y[i]]<<endl;
	}
}

int main(){	
	long long K;
	long long Q;
	long long N;
	fin >> N;
	vector<long long> a((N-1)-1+1);
	vector<long long> c((N-1)-1+1);
	vector<long long> b((N-1)-1+1);
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		fin >> a[i];
		fin >> b[i];
		fin >> c[i];
		a[i]--;b[i]--;
	}
	fin >> Q;
	vector<long long> y(Q-1+1);
	vector<long long> x(Q-1+1);
	fin >> K;
	K--;
	for(int i = 0 ; i <= Q-1 ; i++){
		fin >> x[i];
		fin >> y[i];
		x[i]--;y[i]--;
	}
	solve(N, a, b, c, Q, K, x, y);
	return 0;
}



Measured memory_bytes: 26880