import sys input = sys.stdin.readline N = int(input()) X = [[] for i in range(N)] for i in range(N-1): x, y, w = map(int, input().split()) X[x].append((y, w)) X[y].append((x, w)) P = [-1] * N Q = [0] DE = [0] * N DI = [0] * N while Q: i = Q.pop() for a, w in X[i][::-1]: if a != P[i]: P[a] = i X[a].remove((i, w)) Q.append(a) DE[a] = DE[i] + 1 DI[a] = DI[i] + w D = [[P[i] for i in range(N)]] + [[-1]*N for _ in range(16)] for k in range(1, 17): for i in range(N): a = D[k-1][i] if a > 0: D[k][i] = D[k-1][a] def lca(u, v): if DE[u] < DE[v]: u, v = v, u while DE[u] > DE[v]: d = DE[u] - DE[v] dd = d.bit_length() - 1 u = D[dd][u] if u == v: return u for i in range(17)[::-1]: if D[i][u] != D[i][v]: u = D[i][u] v = D[i][v] return D[0][u] for _ in range(int(input())): x, y, z = map(int, input().split()) xx, yy, zz = lca(y, z), lca(z, x), lca(x, y) print((DI[x]+DI[y]+DI[z])-(DI[xx]+DI[yy]+DI[zz]))