Arboras

Time limit: 2.5s Memory limit: 256MB Input: Output:

Roxanne the mage, after countless hours researching ancient arcana, has decided to go to the local cafe to relax. When she arrived at the old cafe, she saw a strange structure on the wall called an arboras (or tree). Formally, it's a collection of NN vertices numbered with consecutive non-negative integers, where vertex 00 is the root, and all other vertices have a unique parent (vertex vv has parent pvp_v). Since the cafe is run by mages and programmers collectively, the arboras (or tree) is drawn with the root at the top.

The mage is intrigued by this structure, and she decides to pour some magic coffee into one of the vertices. If the coffee is poured into vertex uu, then it will flow downwards, through the subtree rooted at vertex uu. Since it is magic coffee, it doesn't flow randomly: it occupies the longest chain it can possibly occupy, within the subtree rooted at uu, while passing through the vertex uu. The amount of coffee lost when pouring is proportional to the length of the chain the coffee occupies. Roxanne denotes this amount as rur_u. Note that individual edges of the tree might have different lengths.

Task

Roxanne is interested in the amount of coffee she would lose if she poured it in all the vertices of the tree, that is, the sum of rur_u over all vertices uu of the tree. This is not difficult to compute at first, but then the programmers decide to challenge her, and increase the length of certain edges QQ times. Can you help Roxanne find the total length of all the chains occupied by the coffee if poured into all vertices, initially and after each of the QQ updates? Beware! She needs the answers modulo 109+710^9 + 7.

Input

The first line contains integer NN, the number of vertices.

The second line contains N1N - 1 integers: p1,p2l,,pN1p_1, p_2l, \dots , p_{N-1}, where pvp_v is the parent of vertex vv, while vertex 00 is the root.

The third line contains N1N - 1 integers: d1,d2,,dN1d_1, d2, \dots , d_{N-1}, where dvd_v is the length of the edge between vertices vv and pvp_v.

The fourth line contains QQ, the number of updates.

Each of the next QQ lines contain two integers viv_i and addiadd_i, representing the ithi^{th} update: the length of the edge between vertices viv_i and pvip_{v_i} is increased by addiadd_i.

Output

Print Q+1Q + 1 lines: on the i+1thi + 1^{th} line you should print the answer after the ithi^{th} update. On the first line you should print the answer before any updates.

All answers must be printed modulo 109+710^9 + 7.

Constraints

  • 1N100 0001 \leq N \leq 100 \ 000
  • 1Q100 0001 \leq Q \leq 100 \ 000
  • 1di100 000 0001 \leq d_i \leq 100 \ 000 \ 000 for all 1iN11 \leq i \leq N - 1
  • 0pii0 \leq p_i \leq i
  • 1addi1091 \leq add_i \leq 10^9 for all 1iQ1 \leq i \leq Q
# Points Constraints
1 11 1N,Q1 0001 \leq N, Q \leq 1 \ 000
2 13 The height of the tree is at most 5050.
3 31 di=100 000 000d_i = 100 \ 000 \ 000 for all 1iN1, addi=11 \leq i \leq N - 1, \ add_i = 1 for all 1iQ1 \leq i \leq Q
4 45 No additional constraints.

Examples

stdin

5
0 0 1 1
0 0 0 0
10
1 2
2 2
3 2
4 2
4 1
3 1
2 1
1 1
4 1000
2 1000

stdout

0
2
4
8
10
12
13
14
15
2015
3015

Log in or sign up to be able to send submissions!