Tree and Colors

Given a rooted tree with colored vertices and queries f(v,c) counting subtree vertices of color at most c, print the sum of all answers modulo 1e9+7.

Medium6TreeDFSSortingPrefix sumNo attempts yetTime limit2sMemory limit512 MB

Problem

There is a tree with NN vertices and N1N-1 edges. Vertices are numbered from 11 to NN, and the root is vertex 11. There is exactly one path between any two distinct vertices.

Each vertex has one color, represented by an integer between 11 and CC inclusive. For a vertex vv and a color cc, define the query f(v,c)f(v, c) as follows.

f(v,c)f(v, c) is the number of vertices in the subtree rooted at vv whose color is at most cc.

MM queries of the form f(vi,ci)f(v_i, c_i) are given.

Input

The first line contains NN, MM, and CC separated by spaces. NN is the number of vertices, MM is the number of queries, and CC is the number of distinct colors, with 1N2×1051 \le N \le 2 \times 10^5, 1M2×1051 \le M \le 2 \times 10^5, and 1CN1 \le C \le N.

The second line contains NN integers separated by spaces. The ii-th integer is the color of vertex ii, and each value is between 11 and CC inclusive.

Each of the following N1N-1 lines describes an edge of the tree. Each line contains two distinct vertex numbers uu and vv separated by a space, with 1u,vN1 \le u, v \le N.

Each of the following MM lines describes a query. The ii-th line contains viv_i and cic_i separated by a space, with 1viN1 \le v_i \le N and 1ciC1 \le c_i \le C.

Output

Print the sum of the answers to all MM queries modulo 1,000,000,0071,000,000,007.