import sys from collections import deque input = sys.stdin.buffer.readline N = int(input()) T = [[] for _ in range(N)] for _ in range(N - 1): u, v, w = map(int, input().split()) T[u].append((v, w)) T[v].append((u, w)) d = deque([0]) prv = [-1] * N depth = [None] * N depth[0] = 0 acc = [0] * N while d: v = d.pop() depv = depth[v] accv = acc[v] for x, w in T[v]: if depth[x] is None: prv[x] = v depth[x] = depv + 1 acc[x] = accv + w d.append(x) # https://tjkendev.github.io/procon-library/python/graph/lca-doubling.html から拝借しています。 # N: 頂点数 # G[v]: 頂点vの子頂点 (親頂点は含まない) # # - construct # prv[u] = v: 頂点uの一つ上の祖先頂点v # - lca # kprv[k][u] = v: 頂点uの2^k個上の祖先頂点v # depth[u]: 頂点uの深さ (根頂点は0) LV = (N - 1).bit_length() def construct(prv): kprv = [prv] S = prv for k in range(LV): T = [0] * N for i in range(N): if S[i] is None: continue T[i] = S[S[i]] kprv.append(T) S = T return kprv def lca(u, v, kprv, depth): dd = depth[v] - depth[u] if dd < 0: u, v = v, u dd = -dd # assert depth[u] <= depth[v] for k in range(LV + 1): if dd & 1: v = kprv[k][v] dd >>= 1 # assert depth[u] == depth[v] if u == v: return u for k in range(LV - 1, -1, -1): pu = kprv[k][u] pv = kprv[k][v] if pu != pv: u = pu v = pv # assert kprv[0][u] == kprv[0][v] return kprv[0][u] kprv = construct(prv) def dist(u, v): l = lca(u, v, kprv, depth) return acc[u] + acc[v] - 2 * acc[l] Q = int(input()) for _ in range(Q): x, y, z = map(int, input().split()) ans = (dist(x, y) + dist(y, z) + dist(z, x)) // 2 print(ans)