This page is still under construction.

Parts of this page are still being built. What you see may change.

Reasonable Workplace Relationship

Time limit2sMemory limit256 MB

Summary
For each query node, count over its subtree the expected number of leaders who are happy, where a node is happy when its subtree fraction of members exceeding a_i + w_i is zero, modulo 1e9+7.
Level

Medium7 of 10

Topics
DFS, Prefix sum, Sorting, Combinatorics
Solved
No attempts yet

Problem

Subordinates must obey the orders of their superiors unconditionally. If they have any objection, they can raise it later. "If you throw the pot up and down at your subordinates, they can only accept it with patience and full of grievances"... Do these words often seen in workplace novels really reflect the current situation? Let us turn to a more specific simplified model.

Now, we have a workplace relationship model, which is a superior-subordinate relationship. Let us assume there is only one big boss. Since they are called the big boss, they naturally have no superior. The big boss has some subordinates who are directly managed by them, and these subordinates have their own subordinates... Repeat this several times, and we can clearly see that this model is a rooted tree. There are nn people in the model, numbered from 11 to nn. The superior of person ii is the parent of node ii, and the big boss is the root of the tree. We give each person ii an integer a_ia\_i to measure their ability.

A group consists of a person, called the leader of the group, along with all their direct and indirect subordinates. Clearly, a group corresponds to some subtree, and the group leader is the root of that subtree. We know that the management of subordinates by leaders should not be based only on the ability of leaders and subordinates, which is too narrow and not conducive to management. Because of their special status as leaders, leaders obviously still have the so-called prestige to help them manage. So we give each person ii an integer w_iw\_i to measure their prestige.

With prestige and certain ability, leadership can convince the public. Unfortunately, there are always some subordinates whose ability value (a_ia\_i) is greater than the sum of the leader's ability and prestige, and this is very bad. No matter how open-minded a leader is, there will always be some discomfort in their heart.

In order to simplify the problem, consider a group with leader ii. Let the subtree rooted at ii have s_is\_i nodes. Let k_ik\_i be the number of such nodes jj in this subtree that satisfy a_j>a_i+w_ia\_j > a\_i + w\_i. Then person ii has the probability of k_i/s_ik\_i / s\_i of becoming unhappy as a leader (leaders are simple, they are either happy or unhappy). The probabilities for different people are independent.

Now, in order to measure the reasonableness of the company's workplace relationship structure, let us look at some groups. Specifically, we have to answer mm questions. For question ii, consider the group led by person x_ix\_i. We have to count the expected number of people in this group that will be happy as leaders.

Input

The first line of input contains two integers nn and mm (2≤n≤3⋅1052 \le n \le 3 \cdot 10^5, 1≤m≤3⋅1051 \le m \le 3 \cdot 10^5).

The next line contains nn integers p_1,p_2,…,p_np\_1, p\_2, \ldots, p\_n, where p_ip\_i denotes the superior of person ii. If p_i=0p\_i = 0, the ii-th person has no superior, and is the big boss. It is guaranteed that there is exactly one big boss, but it is not guaranteed that the boss is the person number 11. It is also guaranteed that the superior-subordinate relationships form a rooted tree.

The following line contains nn integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n denoting the ability of each person (1≤a_i≤1091 \le a\_i \le 10^9).

The subsequent line contains nn integers w_1,w_2,…,w_nw\_1, w\_2, \ldots, w\_n denoting the prestige of each person (1≤w_i≤1091 \le w\_i \le 10^9).

The ii-th of the following mm lines contains one integer x_ix\_i, asking how many people in the group led by x_ix\_i are expected to be happy.

Output

Print mm lines, with one integer on each: the answers to the queries.

Since the result of a query may not be an integer, you need to output the values modulo 109+710^9 + 7.

Formally, it can be shown that the answer can be represented as a fraction p/qp / q for some coprime non-negative integers pp and qq. You have to print the value p⋅q−1 mod (109+7)p \cdot q^{-1} \bmod (10^9 + 7).

Hint

Person 11 will be happy with probability 1/21 / 2. Person 22 will always be happy.

Examples1

  1. Example 1

    Input
    2 2
    0 1
    1 10
    1 1
    1
    2
    
    Expected output
    500000005
    1