output_description: Print the responses to the queries in Q lines.  
  In the j-th line j(1≤j≤Q), print the response to the j-th query.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N  
      a_1 b_1 c_1  
      :  
      a_{N-1} b_{N-1} c_{N-1}
      Q K
      x_1 y_1
      :  
      x_{Q} y_{Q}
attempt: #include <stdio.h>
  #include <stdlib.h>
  #include <string.h>
  #include <math.h>
  int acs(const void *a, const void *b) { 
    return *(int*)a - *(int*)b;
  } /* 1,2,3,4.. */
  int des(const void *a, const void *b) {
    return *(int*)b - *(int*)a;
  } /* 8,7,6,5.. */
  int cmp_char(const void *a, const void *b) { 
    return *(char*)a - *(char*)b;
  } /* a,b,c,d.. */
  int cmp_str(const void *a, const void *b) {
    return strcmp(*(const char **)a, *(const char **)b);
  } /* aaa,aab.. */
  #define min(a,b) (a < b ? a : b)
  #define max(a,b) (a > b ? a : b)
  #define rep(i, l, r) for (int i = l; i < r; i++)
  #define MAX 100001
  #define MOD 1000000007
  #define INF 1000000009
  typedef long long int lli;
  
  typedef struct list {
    int node;
    int dist;
    struct list *next;
  } list;
  
  list *graph[MAX];
  
  void initGraph(void) {
    for (int i = 0; i < MAX; i++)
      graph[i] = NULL;
  }
  
  void addEdge(int node1, int node2, int dist)
  {
    list *new1 = (list *)malloc(sizeof(list *));
    new1->node = node2;
    new1->dist = dist;
    new1->next = graph[node1];
    graph[node1] = new1;
  
    list *new2 = (list *)malloc(sizeof(list *));
    new2->node = node1;
    new2->dist = dist;
    new2->next = graph[node2];
    graph[node2] = new2;
  }
  
  // 頂点k(根)からの距離
  int kyori[MAX];
  
  void dfs(int n, int p) {
    list *c = graph[n];
    for ( ; c != NULL; c = c->next ) {
      int cn = c->node;
      if ( cn == p ) continue;
      kyori[cn] = kyori[n] + c->dist;
      dfs(cn, n);
    }
  }
  
  int main(void) {
    int n;
    scanf("%d", &n);
    initGraph();
    rep(i, 0, n-1) {
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      addEdge(a, b, c);
    }
    int q, k;
    scanf("%d %d", &q, &k);
    int x[MAX], y[MAX];
    rep(i, 0, q) scanf("%d %d", &x[i], &y[i]);
  
    // 頂点kが根
    kyori[k] = 0;
    dfs(k, 0);
  
    rep(i, 0, q) {
      printf("%d\n", kyori[x[i]] + kyori[y[i]]);
    }
    return 0;
  }
  
problem_description: Statement
  
  You are given a tree with N vertices.  
  Here, a _tree_ is a kind of graph, and more specifically, a connected
  undirected graph with N-1 edges, where N is the number of its vertices.  
  The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of
  c_i.
  
  You are also given Q queries and an integer K. In the j-th query (1≤j≤Q):
  
    * find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.
samples: [{"input": "5\n    1 2 1\n    1 3 1\n    2 4 1\n    3 5 1\n    3 1\n    2 4\n    2 3\n    4 5", "output": "3\n    2\n    4\n    \n\nThe shortest paths for the three queries are as follows:\n\n  * Query 1: Vertex 2 \u2192 Vertex 1 \u2192 Vertex 2 \u2192 Vertex 4 : Length 1+1+1=3\n  * Query 2: Vertex 2 \u2192 Vertex 1 \u2192 Vertex 3 : Length 1+1=2\n  * Query 3: Vertex 4 \u2192 Vertex 2 \u2192 Vertex 1 \u2192 Vertex 3 \u2192 Vertex 5 : Length 1+1+1+1=4\n\n* * *"}, {"input": "7\n    1 2 1\n    1 3 3\n    1 4 5\n    1 5 7\n    1 6 9\n    1 7 11\n    3 2\n    1 3\n    4 5\n    6 7", "output": "5\n    14\n    22\n    \n\nThe path for each query must pass Vertex K=2.\n\n* * *"}, {"input": "10\n    1 2 1000000000\n    2 3 1000000000\n    3 4 1000000000\n    4 5 1000000000\n    5 6 1000000000\n    6 7 1000000000\n    7 8 1000000000\n    8 9 1000000000\n    9 10 1000000000\n    1 1\n    9 10", "output": "17000000000"}]