#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const ll INF = 0x3f3f3f3f3f3f3f3f;
const int MAX_N = 1e5+20;
int n;
int a[MAX_N],b[MAX_N],c[MAX_N];
int Q, K;
int x[MAX_N], y[MAX_N];

struct edge { int to,  cost; };
vector<edge> G[MAX_N];
ll dist[MAX_N];

void add_edge(int from, int to, int cost)
{
	G[from].push_back(edge{to, cost});
	G[to].push_back(edge{from, cost});
}

void dfs(int x, ll d)
{
	dist[x] = d;
	for(auto e : G[x]){
		int t = e.to, c = e.cost;
		if(dist[t] == INF){
			dfs(t, d+c);
		}
	}
}
 
void solve()
{
	for(int i=0;i<n-1;++i) add_edge(a[i],b[i],c[i]);
	memset(dist,0x3f,sizeof(dist));
	dfs(K, 0);
	for(int i=0;i<Q;++i){
		cout<<dist[x[i]]+dist[y[i]]<<'\n';
	}
}

int main()
{
	cin >> n;
	for(int i=0;i<n-1;++i){
		cin >> a[i] >> b[i] >> c[i];
	}
	cin >> Q >> K;
	for(int i=0;i<Q;++i){
		cin >> x[i] >> y[i];
	}
	solve();
	return 0;
}
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 100010
#define INFTY 1e18
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;
struct edge{ll to, cost;};

ll n;
ll dist[MAX];
bool check[MAX];
vector<edge> G[MAX];
void dijkstra(ll s)
{
	priority_queue<P, vector<P>, greater<P>> pq;

	for(ll i = 0; i < n; i++)
	{
		dist[i] = INFTY;
		check[i] = false;
	}

	pq.push(P(0, s));
	dist[s] = 0;
	while (!pq.empty())
	{
		P p = pq.top(); pq.pop();
		ll minv = p.first;
		ll u = p.second;
		check[u] = true;
		if (dist[u] < minv) continue;
		rep(i, G[u].size())
		{
			if (check[G[u][i].to]) continue;
			if (dist[G[u][i].to] > dist[u] + G[u][i].cost)
			{
				dist[G[u][i].to] = dist[u] + G[u][i].cost;
				pq.push(P(dist[G[u][i].to], G[u][i].to));
			}
		}
	}
}

signed main(void)
{
	cin >> n;
	rep(i, n - 1)
	{
		int a, b;
		ll c;
		cin >> a >> b >> c;
		a--; b--;
		G[a].push_back({b, c});
		G[b].push_back({a, c});
	}
	int q, k;
	cin >> q >> k;
	k--;
	dijkstra(k);
	rep(i, q)
	{
		int x, y;
		cin >> x >> y;
		x--; y--;
		cout << dist[x] + dist[y] << endl;
	}
	return 0;
}
