
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cctype>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int, int> PII;
const ll mod = 1000000007;
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
// head
const int iadd[] = {0, 1, 0, -1}, jadd[] = {1, 0, -1, 0};
const int inf = 0x3f3f3f3f;
const int maxn = 5e5 + 5;
struct edge{
	int to, next;
	ll val;
};
edge edges[maxn];
int tot, head[maxn], n;
ll dis[maxn];
short vis[maxn];

void init(){
	memset(head, -1, sizeof(head));
	memset(vis, 0, sizeof(vis));
	tot = 0;
}
void addEdge(int u, int v, ll w){
	edges[tot].to = v;
	edges[tot].val = w;
	edges[tot].next = head[u];
	head[u] = tot++;
}

void dfs(int u, ll val){
	vis[u] = 1; dis[u] = val;
	for(int i = head[u]; i != -1; i = edges[i].next){
		int v = edges[i].to;
		if(!vis[v]) dfs(v, val + edges[i].val);
	}
}

int main(){
	init();
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		int u, v, w;
		scanf("%d %d %d", &u, &v, &w);
		addEdge(u, v, w);
		addEdge(v, u, w);
	}
	int q, k;
	scanf("%d %d", &q, &k);
	dfs(k, 0);
	while(q--){
		int x, y;
		scanf("%d %d", &x, &y);
		printf("%lld\n", dis[x] + dis[y]);
	}
}




