#include <bits/stdc++.h>
#define mem(a) memset(a,0,sizeof(a))
#define N 100010
#define ll long long int
using namespace std;
ll an[N];
struct Node{
  int to;
  ll cost;
};
vector<Node> v[N];
void dfs(int x,int fa){
  for(int i=0;i<v[x].size();i++){
    if(v[x][i].to==fa)
      continue;
    an[v[x][i].to]=an[x]+v[x][i].cost;
    dfs(v[x][i].to,x);
  }
}
int main(){
  int n;
  scanf("%d", &n);
  int x,y;
  ll z;
  for(int i=1;i<n;i++){
    scanf("%d%d%lld",&x,&y,&z);
    v[x].push_back({y,z});
    v[y].push_back({x,z});
  }
  int q,t;
  scanf("%d%d",&q,&t);
  dfs(t,-1);
  while(q--){
    scanf("%d%d",&x,&y);
    printf("%lld\n",an[x]+an[y]);
  }
  return 0;
}