#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;

struct edge{
  ll to, cost;
};

int main()
{
  ll N;
  cin >> N;
  vector<vector<ll>> A(N-1,vector<ll>(3));
  vector<vector<edge>> vec(N,vector<edge> ());
  REP(i, N-1){
    REP(j, 3){
      cin >> A.at(i).at(j);
    }
    A.at(i).at(0)--;
    A.at(i).at(1)--;
    edge e1 = {A.at(i).at(1),A.at(i).at(2)};
    edge e2 = {A.at(i).at(0),A.at(i).at(2)};
    vec.at(A.at(i).at(0)).push_back(e1);
    vec.at(A.at(i).at(1)).push_back(e2);
  }
  
  ll Q,K;
  cin >> Q >> K;
  K--;

  queue<ll> que;
  vector<ll> dist(N,-1);
  que.push(K);
  dist[K]=0;
  while(!que.empty()){
    ll v = que.front();
    que.pop();
    for(auto e:vec.at(v)){
      ll nv = e.to;
      ll ncost = e.cost;
      if(dist[nv]!=-1) continue;

      dist[nv]=dist[v]+ncost;
      que.push(nv);
    }
  }

  vector<ll> ans(Q);
  REP(i,Q){
    ll x,y;
    cin >> x >> y;
    x--;
    y--;
    ans.at(i)=dist[x]+dist[y];
  }

  REP(i,Q){
    cout << ans.at(i) << endl;
  }
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

struct edge {
  ll to, cost;
};

vector<vector<edge>> g;
vector<bool> visited;
vector<ll> dist;

void dfs(int s) {
  visited[s] = true;
  rep(i, g[s].size()) {
    if (visited[g[s][i].to]) continue;
    int to = g[s][i].to, cost = g[s][i].cost;
    dist[to] = dist[s] + cost;
    dfs(to);
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  ll n;
  cin >> n;
  g.resize(n);
  visited.resize(n);
  dist.resize(n);
  rep(i, n) {
    visited[i] = false;
    dist[i] = LINF;
  }
  rep(i, n - 1) {
    ll a, b, c;
    cin >> a >> b >> c;
    --a;
    --b;
    g[a].push_back(edge{b, c});
    g[b].push_back(edge{a, c});
  }
  ll q, k;
  cin >> q >> k;
  --k;
  dist[k] = 0;
  dfs(k);
  rep(i, q) {
    ll x, y, ans = 0;
    cin >> x >> y;
    --x;
    --y;
    cout << dist[x] + dist[y] << endl;
  }
  return 0;
}
