#include <bits/stdc++.h>
using namespace std;

struct edge{long long to, cost;};
vector<edge> graph[100010];
long long depth[100010];

void dfs(long long now, long long prev, long long dist){
  depth[now] = dist;
  for(auto &e : graph[now]){
    if(e.to != prev){
      dfs(e.to, now, dist+e.cost);
    }
  }
}

int main(){
  long long n,q,k,a,b,c,x,y;
  cin >> n;
  for(int i=0;i<n-1;i++){
    cin >> a >> b >> c;
    a--; b--;
    graph[a].push_back({b, c});
    graph[b].push_back({a, c});
  }
  cin >> q >> k;
  k--;
  dfs(k, -1, 0);
  for(int i=0;i<q;i++){
    cin >> x >> y;
    x--; y--;
    cout << depth[x]+depth[y] << endl;
  }
  return 0;
}
