#include #define int long long using namespace std; templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; } class LowestCommonAncestor { public: const int N; vector> G; vector parent,depth; const int LOG; vector> dp; LowestCommonAncestor(vector> G):N(G.size()),G(G),parent(N),depth(N),LOG(32-__builtin_clz(N)) { dfs(0,-1,0); dp.assign(LOG,vector(N,-1)); for(int i=0;idepth[v]) swap(u,v); for(int i=0;i>i&1) v=dp[i][v]; } if(u==v) return u; for(int i=LOG-1;i>=0;i--){ if(dp[i][u]!=dp[i][v]){ u=dp[i][u]; v=dp[i][v]; } } return dp[0][u]; } }; struct edge{int to,cost;}; signed main() { cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vector> G(N); vector> g(N); for(int i=0;i>a>>b>>c; G[a].push_back({b,c}); G[b].push_back({a,c}); g[a].push_back(b); g[b].push_back(a); } vector dist(N); function dfs=[&](int v,int p) { for(edge e:G[v]) if(e.to!=p){ dist[e.to]=dist[v]+e.cost; dfs(e.to,v); } }; dfs(0,-1); LowestCommonAncestor lca(g); auto calc=[&](int u,int v) { return dist[u]+dist[v]-2*dist[lca.query(u,v)]; }; int Q; cin>>Q; while(Q--){ int x,y,z; cin>>x>>y>>z; int ans=calc(x,y)+calc(y,z)+calc(z,x); ans/=2; cout<