A Particle on the Tree

For each query edge (U,V) and final color C, count pairs (start, end) whose shortest path uses that edge in that direction and whose arrival color matches C.

Medium7TreeDFSPrefix sumMathNo attempts yetTime limit1sMemory limit128 MB

Problem

A tree is a connected graph with no cycle. The picture above shows a tree shaped particle accelerator and one special particle placed on a vertex of it. This particle, called an RB particle, is red while it is stable. Once it becomes unstable its color changes every second: red turns black, and black turns red.

Taekhee runs a simple experiment with it. He first fixes a start vertex and an end vertex inside the accelerator, takes one stable particle, makes it unstable, and puts it on the start vertex. That preparation takes no time. Right after that the particle moves toward the end vertex along a shortest path, and crossing one edge takes exactly 1 second.

Taekhee ran MM experiments but forgot to write the results down. For each experiment he remembers two things: that the particle crossed the edge between vertices UU and VV in the direction from UU to VV, and the color of the particle when it arrived at the end vertex.

Restoring the report means counting, for each experiment, how many (start vertex, end vertex) pairs agree with what he remembers. Compute that count for him.

Input

The first line has the number of vertices of the accelerator NN (2N1052 \le N \le 10^5) and the number of experiments MM (1M1051 \le M \le 10^5).

Each of the next N1N-1 lines has two vertices UU VV joined by an edge. (1U,VN1 \le U, V \le N, UVU \ne V)

Each of the next MM lines has the information known about one experiment as UU VV CC. (1U,VN1 \le U, V \le N, CC is 0 or 1, UVU \ne V)

This means that in that experiment the particle crossed the edge between UU and VV in the direction from UU to VV, and the color at the end vertex was red when C=0C = 0 and black when C=1C = 1.

The particle is always red at the start vertex. For every UU and VV given in an experiment, the tree is guaranteed to contain the edge between UU and VV.

The accelerator given in the input is always a valid tree.

Output

Print MM lines.

On line ii, print the number of distinct (start vertex, end vertex) pairs that were possible in experiment ii.

The value can exceed the range of a 32 bit signed integer during the computation.