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

struct edge{
  int to;
  ll cost;
};

vector<edge> tree[100010];
ll depth[100010];

void dfs(int v, int p,ll d){
  depth[v]=d;
  for(auto &e : tree[v]){
    if(e.to == p)continue;
    dfs(e.to,v,d+e.cost);
  }
}

int main() {
  int n;
  cin >> n;
  rep(i,n-1){
    int a,b,c;
    cin >> a >> b >> c;
    a--,b--;
    tree[a].push_back({b,c});
    tree[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 << depth[x] + depth[y] << endl;
  }
  return 0;
}
