// NOTE: it is recommended to use this even if you don't understand the following code.

#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

#define MAXQ 100000
#define MAXN 100000

int       N, Q, i;
int       A[MAXN - 1], B[MAXN - 1], W[MAXN - 1];
int       U[MAXQ], V[MAXQ], X[MAXQ];
long long ans[MAXQ + 1];

int main() {
    // uncomment the two following lines if you want to read/write from files
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    assert(1 == scanf("%d", &N));

    for (i = 0; i < N - 1; ++i)
        assert(3 == scanf("%d%d%d", &A[i], &B[i], &W[i]));

    assert(1 == scanf("%d", &Q));

    for (i = 0; i < Q; ++i)
        assert(3 == scanf("%d%d%d", &U[i], &V[i], &X[i]));



    // INSERT YOUR CODE HERE


    for (i = 0; i < Q + 1; ++i)
        printf("%lld ", ans[i]);
    printf("\n");

    return 0;
}
