Barbarians

A tree's edges are deleted one by one, each deletion multiplies each vertex's anger by (reachable before) - (reachable after) + 1, and after each deletion the total anger is printed modulo 1e9+7.

Hard8TreeUnion-findMathImplementationNo attempts yetTime limit4sMemory limit512 MB

Problem

A country is made of nn islands joined by n1n - 1 bridges. For any two islands there is exactly one way to travel from one to the other without visiting any island twice.

Barbarians have attacked the country. They worked out that the bridges are the weak point, so they destroy the bridges one after another. The people of island ii start with anger aia_i.

The anger changes like this. Take an island xx. Let aa be the number of islands the people of xx can reach before some bridge is destroyed, and let bb be the number they can reach after it is destroyed. Both counts include island xx itself. The anger at island xx is then multiplied by ab+1a - b + 1.

You get n1n - 1 requests. Each request holds two integers uu and vv. Let resres be the answer to the previous request, with res=0res = 0 for the first request. The request destroys the bridge between island u+resu + res and island v+resv + res.

Let bib_i be the anger at island ii after that bridge is destroyed. Set resres to (b1+b2++bn)(b_1 + b_2 + \cdots + b_n) modulo 109+710^9 + 7 and print that value.

The first example shows how the request format works. There are 5 islands and the starting anger is 1 2 3 4 5. The first request uses res=0res = 0, so it destroys the bridge between islands 3 and 1. The anger at islands 1 and 2 is multiplied by 4 and the anger at the other three islands is multiplied by 3, so the anger becomes 4 8 9 12 15. The sum is 48, so resres becomes 48 and 48 is printed. The next request holds 47-47 and 46-46, so the bridge it destroys joins island (47)+48=1(-47) + 48 = 1 and island (46)+48=2(-46) + 48 = 2.

Input

The first line contains the number of islands nn (2n2×1052 \le n \le 2 \times 10^5).

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n, the starting anger (1ai109+61 \le a_i \le 10^9 + 6).

Each of the next n1n - 1 lines contains two integers uiu_i and viv_i describing a bridge (1ui,vin1 \le u_i, v_i \le n). It is guaranteed that there is exactly one way to travel between any two islands.

Each of the next n1n - 1 lines contains one request in the format described above. The bridge a request points to always exists and has not been destroyed yet, and both of its endpoints are between 1 and nn.

Output

For each request print the value of resres, one per line, in the order of the requests.