#include //#include //#include using namespace std; //using namespace boost::multiprecision; //using namespace atcoder; #define rep(i,n) for(int i=0;i<(n);++i) #define lep(i,n) for(long long i=0;i<(n);++i) #define all(x) (x).begin(),(x).end() #define equals(a,b) (fabs((a)-(b)); using pd=pair; using vi=vector; using vii=vector>; using vl=vector; using vll=vector>; using vpi=vector>; using vs=vector; using vss=vector>; using vst=vector>; const int dx[4]={1,0,-1,0}; const int dy[4]={0,1,0,-1}; const int inf=1<<30; const ll infl=1LL<<60; const double eps=(1e-10); const int mod=1000000007; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } struct LCA { typedef ll TT; int n, bi; vi dep; vector d; vii to, co, pa; LCA(int n):n(n),dep(n),d(n),to(n),co(n){} void add(int a, int b, int c=1) { to[a].push_back(b); co[a].push_back(c); to[b].push_back(a); co[b].push_back(c); } void dfs(int v, int ndep=0, TT nd=0, int p=-1) { dep[v] = ndep; d[v] = nd; pa[0][v] = p; rep(i,(to[v]).size()) { int u = to[v][i]; if (u == p) continue; dfs(u,ndep+1,nd+co[v][i],v); } } void init(int root=0) { bi = 0; while (1<= 0; --i){ if(1<= 0; --i){ if (pa[i][a] != pa[i][b]) a = pa[i][a], b = pa[i][b]; } return pa[0][a]; } TT dist(int a, int b){ int c = lca(a,b); return d[a]+d[b]-d[c]*2; } }; int main(){ int n; cin>>n; LCA g(n); rep(i,n-1){ int a,b,c; cin>>a>>b>>c; g.add(a,b,c); } g.init(); int k; cin>>k; rep(i,k){ int a,b,c; cin>>a>>b>>c; ll ans=(ll)g.dist(a,b)+(ll)g.dist(b,c)+(ll)g.dist(c,a); ans/=2; cout<