output_description: Print the number of blocks in K-city.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      n m
attempt: from sys import stdin
  
  input = stdin.readline
  
  
  def BFS(K, path, N):
      """リストのリスト道順path,頂点の個数Nが与えられたとき, 頂点Kから各頂点までの距離をlistで返す"""
      import queue
  
      dist = [-1] * N
      dist[K] = 0
      que = queue.Queue()
      que.put(K)
      while que.qsize():
          label = que.get()
          for i, c in path[label]:
              if dist[i] == -1:
                  dist[i] = dist[label] + c
                  que.put(i)
      return dist
  
  
  N = int(input())
  path = [[] for i in range(N)]
  for i in range(N - 1):
      a, b, c = map(int, input().split())
      path[a - 1] += [(b - 1, c)]
      path[b - 1] += [(a - 1, c)]
  Q, K = map(int, input().split())
  xy = [list(map(int, input().split())) for i in range(Q)]
  distance = BFS(K - 1, path, N)
  for i in range(Q):
      print(distance[xy[i][0] - 1] + distance[xy[i][1] - 1])
  
problem_description: Statement
  
  In _K-city_ , there are n streets running east-west, and m streets running
  north-south. Each street running east-west and each street running north-south
  cross each other. We will call the smallest area that is surrounded by four
  streets a block. How many blocks there are in K-city?
samples: [{"input": "3 4", "output": "6\n    \n\nThere are six blocks, as shown below:\n\n![9179be829dc9810539213537d4c7398c.png](https://atcoder.jp/img/abc069/9179be829dc9810539213537d4c7398c.png)\n\n* * *"}, {"input": "2 2", "output": "1\n    \n\nThere are one block, as shown below:\n\n![997bfafa99be630b54d037225a5c68ea.png](https://atcoder.jp/img/abc069/997bfafa99be630b54d037225a5c68ea.png)"}]