from collections import deque n = int(input()) g = [[] for _ in range(n)] for _ in range(n - 1): a, b, c = map(int, input().split()) a -= 1 b -= 1 g[a].append((b, c)) g[b].append((a, c)) k = n.bit_length() src = 0 doub = [[src for _ in range(k)] for _ in range(n)] depth = [None for _ in range(n)] depth[src] = 0 cost = [0 for _ in range(n)] dq = deque() dq.appendleft(src) while len(dq) > 0: cur = dq.pop() for nxt, c in g[cur]: if not depth[nxt] is None: continue depth[nxt] = depth[cur] + 1 cost[nxt] = cost[cur] + c doub[nxt][0] = cur dq.appendleft(nxt) for i in range(1, k): for v in range(n): doub[v][i] = doub[doub[v][i - 1]][i - 1] def lca(u, v): ut = u vt = v if depth[ut] > depth[vt]: ut, vt = vt, ut diff = depth[vt] - depth[ut] for i in range(k): if (diff >> i) & 1 != 0: vt = doub[vt][i] if ut != vt: for i in range(k - 1, -1, -1): if doub[ut][i] != doub[vt][i]: ut = doub[ut][i] vt = doub[vt][i] if ut != vt: ut = doub[ut][0] return ut q = int(input()) for _ in range(q): s, t = map(int, input().split()) s -= 1 t -= 1 l = lca(s, t) print(cost[s] + cost[t] - 2 * cost[l])