Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
sys.setrecursionlimit(100000)
N = int(input())
graph = [[] for _ in range(N+1)]
for i in range(1, N):
    tmpa, tmpb, tmpc = map(int, input().split())
    graph[tmpa].append((tmpb, tmpc))
    graph[tmpb].append((tmpa, tmpc))

Q, K = map(int, input().split())
question = [[] for _ in range(Q+1)]
for i in range(1, Q+1):
    question[i] = list(map(int, input().split()))

#print(graph)
#print(question)
seen = [False] * (N+1)
dist = [0] * (N+1)
#Kからdfs
def dfs(here, seen, kyori):
    seen[here] = True
    dist[here] = kyori
    #print(f"here:{here} kyori:{kyori}")
    for node in graph[here]:
        nextkyori = kyori
        if not seen[node[0]]:
            nextkyori += node[1]
            dfs(node[0], seen, nextkyori)

dfs(K, seen, 0)
for quest in question[1:]:
    print(dist[quest[0]] + dist[quest[1]])


Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(1000000)
N = int(input())
graph = [[] for _ in range(N+1)]
for i in range(1, N):
    tmpa, tmpb, tmpc = map(int, input().split())
    graph[tmpa].append((tmpb, tmpc))
    graph[tmpb].append((tmpa, tmpc))

Q, K = map(int, input().split())
question = [[] for _ in range(Q+1)]
for i in range(1, Q+1):
    question[i] = list(map(int, input().split()))

#print(graph)
#print(question)
seen = [False] * (N+1)
dist = [0] * (N+1)
#Kからdfs
def dfs(here, seen, kyori):
    seen[here] = True
    dist[here] = kyori
    #print(f"here:{here} kyori:{kyori}")
    for node in graph[here]:
        nextkyori = kyori
        if not seen[node[0]]:
            nextkyori += node[1]
            dfs(node[0], seen, nextkyori)

dfs(K, seen, 0)
for quest in question[1:]:
    print(dist[quest[0]] + dist[quest[1]])

Buggy python submission (verdict: Runtime Error):
from collections import deque
N = int(input())
graph = [[] for _ in range(N+1)]
for i in range(1, N):
    tmpa, tmpb, tmpc = map(int, input().split())
    graph[tmpa].append((tmpb, tmpc))
    graph[tmpb].append((tmpa, tmpc))

Q, K = map(int, input().split())
question = [[] for _ in range(Q+1)]
for i in range(1, Q+1):
    question[i] = list(map(int, input().split()))

#print(graph)
#print(question)
seen = [False] * (N+1)
dist = [0] * (N+1)
#Kからdfs
def dfs(here, seen, kyori):
    seen[here] = True
    dist[here] = kyori
    #print(f"here:{here} kyori:{kyori}")
    for node in graph[here]:
        nextkyori = kyori
        if not seen[node[0]]:
            nextkyori += node[1]
            dfs(node[0], seen, nextkyori)

dfs(K, seen, 0)
for quest in question[1:]:
    print(dist[quest[0]] + dist[quest[1]])


Fixed submission:
from collections import deque
import sys
sys.setrecursionlimit(1000000)
N = int(input())
graph = [[] for _ in range(N+1)]
for i in range(1, N):
    tmpa, tmpb, tmpc = map(int, input().split())
    graph[tmpa].append((tmpb, tmpc))
    graph[tmpb].append((tmpa, tmpc))

Q, K = map(int, input().split())
question = [[] for _ in range(Q+1)]
for i in range(1, Q+1):
    question[i] = list(map(int, input().split()))

#print(graph)
#print(question)
seen = [False] * (N+1)
dist = [0] * (N+1)
#Kからdfs
def dfs(here, seen, kyori):
    seen[here] = True
    dist[here] = kyori
    #print(f"here:{here} kyori:{kyori}")
    for node in graph[here]:
        nextkyori = kyori
        if not seen[node[0]]:
            nextkyori += node[1]
            dfs(node[0], seen, nextkyori)

dfs(K, seen, 0)
for quest in question[1:]:
    print(dist[quest[0]] + dist[quest[1]])