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

const
    MAXQ = 100000;
    MAXN = 100000;

var
    N, Q, i : LongInt;
    A, B, W : Array[0..MAXN - 1-1] of LongInt;
    U, V, X : Array[0..MAXQ-1] of LongInt;
    ans     : Array[0..MAXQ + 1-1] of Int64;

begin
{
    uncomment the two following lines if you want to read/write from files
    assign(input,  'input.txt');  reset(input);
    assign(output, 'output.txt'); rewrite(output);
}

    ReadLn(N);

    for i:=0 to N - 1-1 do
        ReadLn(A[i], B[i], W[i]);

    ReadLn(Q);

    for i:=0 to Q-1 do
        ReadLn(U[i], V[i], X[i]);

    for i := 0 to MAXQ + 1-1 do ans[i] := 0;

    { INSERT YOUR CODE HERE }


    for i:=0 to Q + 1-1 do
        Write(ans[i], ' ');
    WriteLn();

end.
