You are given a tree with $$$n$$$ nodes, rooted at node $$$1$$$. Each node $$$i$$$ contains $$$k_i$$$ items, all having the same price $$$p_i$$$.
You need to process several queries. Each query is described by four integers: $$$u$$$, $$$d$$$, $$$p_{\text{lower}}$$$, and $$$p_{\text{upper}}$$$.
For each query, you must determine the number of items that satisfy all of the following conditions:
The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of nodes in the tree.
Each of the next $$$n - 1$$$ lines contains two integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le n$$$; $$$a \ne b$$$), denoting an edge between nodes $$$a$$$ and $$$b$$$.
Then $$$n$$$ lines follow. The $$$i$$$-th of these lines contains two integers $$$k_i$$$ and $$$p_i$$$ ($$$0 \le k_i \le 10^5$$$, $$$1 \le p_i \le 10^9$$$) — the number of items and their common price at node $$$i$$$.
Then an integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) is given — the number of queries.
In the $$$i$$$'th line of the next $$$q$$$ lines contains four integers $$$U_i ~(1 \le U_i \le n)$$$, $$$D_i~(0 \le D_i \le n - 1)$$$, $$$PL_i$$$ and $$$PU_i~(1 \le PL_i, ~PU_i \le 10^9)$$$.
Let $$$ans_0 = 0$$$. For each query $$$i$$$, the actual parameters are decoded as follows: $$$$$$u = ((U_i + ans_{i-1}) \mod n) + 1,$$$$$$ $$$$$$d = (D_i + ans_{i-1}) \mod n,$$$$$$ $$$$$$p_{\text{lower}} = ((PL_i + ans_{i-1}) \mod 10^9) + 1,$$$$$$ $$$$$$p_{\text{upper}} = ((PU_i + ans_{i-1}) \mod 10^9) + 1.$$$$$$
If $$$p_{\text{lower}} \gt p_{\text{upper}}$$$, then these two values are swapped.
After decoding $$$1 \le u \le n$$$, $$$0 \le d \le n - 1$$$, $$$1 \le p_{\text{lower}} \le p_{\text{upper}} \le 10^9$$$.
After printing the answer to query $$$i$$$, it becomes $$$ans_i$$$, which is then used in decoding query $$$i+1$$$.
For each query, print a single integer — the number of items satisfying the conditions above.
101 22 33 44 51 61 73 82 93 103 48 58 83 88 70 80 11 94 54 1057 5 1 1010 5 7 102 1 10 108 7 5 102 5 7 10
20 0 0 0 8
| Name |
|---|


