N = int(input()) E = [[]for _ in range(N)] for _ in range(N-1): u,v,w = map(int, input().split()) E[u].append((v, w)) E[v].append((u, w)) from collections import deque inf = 10**15 dist = [inf]*N dist[0] = 0 q = deque() q.append((0, 0)) while q: temp = q.popleft() u = temp[0] d = temp[1] for l in E[u]: if dist[l[0]] < inf: continue dist[l[0]] = d+l[1] q.append((l[0], d+l[1])) #LCA par = [-1]*N rnk = [-1]*N par[0] = 0 rnk[0] = 0 q = deque() q.append((0, 0)) while q: temp = q.popleft() v = temp[0] r = temp[1] for l in E[v]: if par[l[0]] < 0: par[l[0]] = v rnk[l[0]] = r+1 q.append((l[0], r+1)) par[0] = 0 LV = (N-1).bit_length() kpar = [par] for k in range(LV): T = [0]*N for i in range(N): if par[i] == 0: continue T[i] = par[par[i]] kpar.append(T) par = T def lca(u, v): if rnk[u] > rnk[v]: u, v = v, u d = rnk[v]-rnk[u] for i in range(LV+1): if d&1: v = kpar[i][v] d >>= 1 if u == v: return u for k in range(LV-1, -1, -1): pu = kpar[k][u] pv = kpar[k][v] if pu != pv: u = pu v = pv return kpar[0][u] Q = int(input()) for _ in range(Q): x,y,z = map(int, input().split()) a = lca(x, y) b = lca(y, z) c = lca(z, x) if rnk[a] >= rnk[b] and rnk[a] >= rnk[c]: ans = dist[x]+dist[y]-2*dist[a] d = lca(a, z) ans += dist[a]+dist[z]-dist[d] elif rnk[b] >= rnk[c] and rnk[b] >= rnk[a]: ans = dist[y]+dist[z]-2*dist[b] d = lca(b, x) ans += dist[b]+dist[x]-dist[d] else: ans = dist[z]+dist[x]-2*dist[c] d = lca(c, y) ans += dist[c]+dist[y]-dist[d] print(ans)