Given a tree T with n vertices and n−1 weighted edges, initially, vertex i is assigned color i for 1≤i≤n. Since Marisa is dissatisfied with the structure of the tree T, she decides to shuffle the tree T to obtain a new tree T′, where vertex i will have the color pi (1≤i≤n), and p1,p2,…,pn is a permutation of 1,2,…,n. After shuffling the tree T, Marisa provides q queries. Each query i consists of ui,vi,xi. For the simple path from ui to vi in tree T, let the set of distinct colors on this path be s1,s2,…,sk. Compute the total distance from xi to every vertex with color sj in tree T′, for all 1≤j≤k.
Input
5 2
5 3 2 1 4
1 2 1
2 3 1
2 4 2
1 5 2
3 4 1
5 1 5
Output
5
7