import sys sys.setrecursionlimit(120000) class segment_tree: def __init__(self,n): self.size = 1 while self.size < n: self.size *= 2 self.dat = [0]*(self.size*2) def update(self,pos,x): pos += self.size self.dat[pos] = x while pos >= 2: pos //= 2 self.dat[pos] = min(self.dat[pos*2], self.dat[pos*2+1]) def query(self,l,r,a,b,u): if r <= a or b <= l: return 10**15 if l <= a and b <= r: return self.dat[u] m = (a+b)//2 answerl = self.query(l,r,a,m,u*2) answerr = self.query(l,r,m,b,u*2+1) return min(answerl,answerr) N = int(input()) G = [list() for i in range(N)] for i in range(N-1): u, v, w = map(int,input().split()) G[u].append((v,w)) G[v].append((u,w)) def dfs(i,k): visited[i] = True place[i] = len(dist) dist.append(k) for e in G[i]: if visited[e[0]] == False: dfs(e[0],k+e[1]) dist.append(k) visited = [False]*N place = [None]*N dist = [] dfs(0,0) st = segment_tree(len(dist)) for i in range(len(dist)): st.update(i,dist[i]) Q = int(input()) for i in range(Q): x, y, z = map(int,input().split()) l1 = min(place[x],place[y]) r1 = max(place[x],place[y]) l2 = min(place[x],place[z]) r2 = max(place[x],place[z]) l3 = min(place[y],place[z]) r3 = max(place[y],place[z]) v1 = st.query(l1,r1+1,0,st.size,1) v2 = st.query(l2,r2+1,0,st.size,1) v3 = st.query(l3,r3+1,0,st.size,1) print(dist[place[x]] + dist[place[y]] + dist[place[z]] - v1 - v2 - v3)