#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long int ll;

struct edge {
  int to;
  ll cost;
};

vector<edge> g[100010];
ll ans[100010];

void dfs(int v, int p, ll d) {
  ans[v] = d;
  rep(i, (int)g[v].size()) {
    if (g[v][i].to == p) continue;
    dfs(g[v][i].to, v, d + g[v][i].cost);
  }
}

int main() {
  int n; cin >> n;
  rep(i, n-1) {
    int a, b, 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--;
  dfs(k, -1, 0);
  rep(i, q) {
    int x, y; cin >> x >> y; x--; y--;
    cout << ans[x] + ans[y] << endl;
  }
  return 0;
}