#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"from collections import*\n"
"input=open(0).readline\n"
"n=int(input())\n"
"e=[[]for _ in range(n)]\n"
"for _ in range(n-1):\n"
"    a,b,c=map(int,input().split())\n"
"    e[a-1].append((b-1,c))\n"
"    e[b-1].append((a-1,c))\n"
"q,k=map(int,input().split())\n"
"d=[0]*n\n"
"f=[0]*n\n"
"f[k-1]=1\n"
"s=deque([(k-1,0)])\n"
"while s:\n"
"    t,c=s.pop()\n"
"    f[t]=1\n"
"    d[t]=c\n"
"    for i,v in e[t]:\n"
"        if not f[i]:\n"
"            s.append((i,v+c))\n"
"for _ in range(q):\n"
"    x,y=map(int,input().split())\n"
"    print(d[x-1]+d[y-1])\n"
"\"";
  system(s);
  return 0;
}            