#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size());
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9+7;
using Graph = vector<vector<P>>;
Graph G;
ll dist[100100];
void dfs(int u, int p, ll d) {
  dist[u] = d;
  for (auto v : G[u]) {
    if (v.first == p) continue;
    dfs(v.first,u,d+v.second);
  }
}

int main() {
  int n;
  cin >> n;
  G.resize(n);

  rep(i,n-1) {
    int a, b, c;
    cin >> a >> b >> c;
    G[--a].push_back({--b,c});
    G[b].push_back({a,c});
  }

  int q,k;
  cin >> q >> k;
  dfs(--k,-1,0);

  rep(i,q) {
    int x, y;
    cin >> x >> y;
    cout << dist[--x] + dist[--y] << endl;
  }
  return 0;
}