#include using namespace std; #define REP(i, n) for(int (i) = 0; (i) < (n); (i)++) #define MAX(a, b) ((a) > (b) ? (a) : (b)) #define MAX3(a, b, c) (MAX((a), MAX(b, c))) #define MIN(a, b) ((a) < (b) ? (a) : (b)) typedef long long ll; #define N_MAX 100000 int parent[N_MAX][2]; int main(void){ int n; cin >> n; REP(i, n-1){ int u, v, w; cin >> u >> v >> w; parent[MAX(u, v)][0] = MIN(u, v); parent[MAX(u, v)][1] = w; } int q; cin >> q; vector v(3); REP(i, q){ ll ans = 0; cin >> v[0] >> v[1] >> v[2]; while(1){ int max = MAX3(v[0], v[1], v[2]); REP(j, 3){ if(v[j] == max){ v[j] = parent[v[j]][0]; } } ans += parent[max][1]; if(v[0] == v[1] && v[0] == v[2]) break; } cout << ans << endl; } return 0; }