#include using namespace std; #define rep(i,n) for(ll i=0;i=0;i--) #define perl(i,r,l) for(ll i=r-1;i>=l;i--) #define fi first #define se second #define pb push_back #define ins insert #define pqueue(x) priority_queue,greater> #define all(x) (x).begin(),(x).end() #define CST(x) cout<; using vvl=vector>; using pl=pair; using vpl=vector; using vvpl=vector; const ll MOD=1000000007; const ll MOD9=998244353; const int inf=1e9+10; const ll INF=4e18; const ll dy[8]={-1,0,1,0,1,1,-1,-1}; const ll dx[8]={0,-1,0,1,1,-1,1,-1}; template inline bool chmax(T &a, T b) { return ((a < b) ? (a = b, true) : (false)); } template inline bool chmin(T &a, T b) { return ((a > b) ? (a = b, true) : (false)); } struct Edge{ ll to,weight; }; using Graph=vector>; struct LCA{ vector> parent; vvl dp; vector dist; LCA(const Graph &G,int root=0){ int V=G.size(); int K=1; while((1<(V,-1)); dp.assign(K,vl(V)); dist.assign(V,-1); dfs(G,root,-1,0); for(int k=0;k+1>k&1){ u=parent[k][u]; } } if(u==v)return u; for(int k=K-1;k>=0;k--){ if(parent[k][u]!=parent[k][v]){ u=parent[k][u]; v=parent[k][v]; } } return parent[0][u]; } ll getsum(ll u,ll v){ if(dist[u]>k&1){ ret+=dp[k][u]; u=parent[k][u]; } } if(u==v)return ret; for(int k=K-1;k>=0;k--){ if(parent[k][u]!=parent[k][v]){ ret+=dp[k][u]+dp[k][v]; u=parent[k][u]; v=parent[k][v]; } } return ret+dp[0][u]+dp[0][v]; } }; int main(){ ll n;cin >> n; Graph g(n); rep(i,n-1){ ll a,b,c;cin >> a >> b >> c; g[a].push_back({b,c}); g[b].push_back({a,c}); } LCA lca(g); ll q;cin >> q; while(q--){ ll a,b,c;cin >> a >> b >> c; ll l=lca.query(a,b)^lca.query(b,c)^lca.query(c,a); cout << lca.getsum(a,l)+lca.getsum(b,l)+lca.getsum(c,l) <