#include using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i) #define irreps(i, m, n) for (long long i = ((long long)(n)-1); i > (long long)(m); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v+n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cinline(n) getline(cin,n); #define replace_all(s, b, a) replace(s.begin(),s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) (long long)(x.size()) using ll = long long; using vi = vector; using vvi = vector; using vll = vector; using vvll = vector; using pii = pair; using pll = pair; using vs = vector; using vpll = vector>; using vtp = vector>; using vb = vector; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template using vc=vector; template using vvc=vc>; const ll INF = 1e9+10; const ll MOD = 1e9+7; const ll LINF = 1e18; /** * 3頂点を辺数が最小になるように結ぶ * その際の辺のコストを求める * lcaを重みを含むように拡張する * a,b,cを接続する * a,b b,c or a,b a,c or b,c a,c .. どの頂点を中間点とするか * 3頂点のコスト: 2頂点のコスト+depth(残り)-lca? * 位置関係で変わる * どういう順でもよい * dist(a,b)+dist(a,c)-dist(a,lca(a,b))で求まる? * lcaを求めるには辺の数について見る必要がある=>重みでは高さを揃える、lcaの一歩手前まで遡るができない * 単純にdist(a,b),dist(a,c)のうち大きい方+小さい方-dist(小さいの組のlca,a(b)) */ class LCA{ private: int n; int root; int k; // n<=2^kとなる最小のk vc> dp; // dp[i][j]:=要素jの2^i上の要素 vc depth; // depth[i]:=rootに対する頂点iの深さ vll dist; public: LCA(int _n, int _root, vc>> _G){ n=_n; root=_root; k=1; int nibeki=2; while(nibeki>(k+1, vc(n, -1)); depth.resize(n); dist.resize(n); function _dfs=[&](int v, int p){ dp[0][v]=p; for(auto np: _G[v]){ int nv, c; tie(nv,c)=np; if(nv==p) continue; depth[nv]=depth[v]+1; dist[nv]=dist[v]+c; _dfs(nv, v); } }; _dfs(root, -1); // ダブリング rep(i,k){ rep(j,n){ dp[i+1][j]=dp[i][dp[i][j]]; } } } int get(int u, int v){ if(depth[u]>i)&1) u=dp[i][u]; } if(u==v) return u; rrep(i,k){ if(dp[i][u]!=dp[i][v]){ u=dp[i][u], v=dp[i][v]; } } return dp[0][u]; } ll getDist(int u, int v){ int lca=get(u,v); return dist[u]+dist[v]-2*dist[lca]; } int getDist(int a, int b, int c){ ll x=getDist(a,b), y=getDist(a,c); if(x>=y){ // cとa,bのlcaの内、cと近い方を採用 ll d=min(getDist(c,get(c,a)), getDist(c,get(c,b))); return x+d; }else{ // bとa,cのlcaの内、bと近い方を採用 ll d=min(getDist(b,get(b,a)), getDist(b,get(b,c))); return y+d; } } }; signed main() { cin.tie( 0 ); ios::sync_with_stdio( false ); ll n; cin>>n; vc>> G(n); rep(i,n-1){ ll a,b,c; cin>>a>>b>>c; G[a].emplace_back(b,c); G[b].emplace_back(a,c); } auto lca=LCA(n, 0, G); ll q; cin>>q; while(q--){ ll a,b,c; cin>>a>>b>>c; cout<