#include <cstdio>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
#include <iostream>
using namespace std;

//////////////////////////////////////
///edge
typedef struct edge {
  int y;        /* adjancency info */
  int type;        /* edge type by dfs */
  long long int weight;     /* edge weight, if any */
  struct edge *next;    /* next edge in list */
} edge;

//////////////////////////////////////
///graph
#define MAXV    100001   /* maximum number of vertices */

typedef struct graph{
  vector< edge* > edges;
  vector< int > deg;
  int nv;
  int ne;
  int dir;

  void init_graph(int v, bool d){
    nv = v;
    ne = 0;
    dir = d;
    for (int i=0; i<=MAXV; i++) deg.push_back(0);
    for (int i=0; i<=MAXV; i++) edges.push_back(NULL);
  }

  void insert_edge(int x, int y, long long int w,bool dir){
    edge *p = (edge*)malloc(sizeof(edge));

    p->weight = w;
    p->y = y;
    p->type = -1;
    p->next = edges[x];

    edges[x] = p;
    deg[x] ++;

    if (dir == false)
      insert_edge(y,x,w,true);
    else
      ne ++;
  }


  ///varibles for BFS
  vector<bool> processed,discovered;
  vector<int> parent,depth,entry_time,exit_time;
  vector<long long int> way;
  int t;                   /* current event time */

  //-----------------------------------------------------------
  void process_vertex_early(int v){
  }
  //-----------------------------------------------------------
  void process_vertex_late(int v){
  }
  //-----------------------------------------------------------
  void process_edge(int x, int y){
  }



  bool unsearched = true;
  void initialize_search(){
    t = 0;
    for (int i=0; i<=nv; i++) {
      if(unsearched){
        processed.push_back(false);
        discovered.push_back(false);
        parent.push_back(-1);
        depth.push_back(-1);
        entry_time.push_back(-1);
        exit_time.push_back(-1);
        way.push_back(0);
      }else{
        processed[i] = discovered[i] = false;
        parent[i] = depth[i] = entry_time[i] = exit_time[i] = -1;
        way[i] = 0;
      }
    }
    unsearched = false;
  }


  void dfs(int v){
    edge *p;      /* temporary pointer */
    int y;        /* successor vertex */

    t = t+1;
    entry_time[v] = t;
    discovered[v] = true;
//    process_vertex_early(v);

    p = edges[v];
    while (p != NULL) {
      y = p->y;
      if (!discovered[y]) {
        parent[y] = v;
        way[y] = p->weight + way[v];
//        process_edge(v,y);
//        p->type = edge_classification(v,y);
        dfs(y);
      }
      else if ((!processed[y]) || (dir)){
//        process_edge(v,y);
//        p->type = edge_classification(v,y);
      }

      p = p->next;
    }
//    process_vertex_late(v);
    t = t+1;
    exit_time[v] = t;
    processed[v] = true;
  }

} graph;



int main()
{
  int n; cin >> n;
  graph g;
  g.init_graph(n,1);
  for(int i=0;i<n-1;i++){
    int x,y;
    long long int w;
    cin >> x >> y >> w;
    x--;  y--;
    g.insert_edge(x,y,w,0);
  }

  int q,k;
  cin >> q >> k;  k--;
  g.initialize_search();
  g.dfs(k);


  for(int i=0;i<q;i++){
    int x,y;
    cin >> x >> y;
    x--;
    y--;
    cout << g.way[x] + g.way[y] << endl;
  }

  return 0;
}

Measured memory_bytes: 18292