#ds1004. 动态树

动态树

Dynamic Tree

Problem Description

Do not forget that this is a dynamic tree — it is dynamic at every moment. Xiao Ming asks you to maintain two kinds of events on this tree.

  1. 0 u delta: the tree grows some fruits, i.e. every node in the subtree rooted at uu grows deltadelta fruits.
  2. 1 k u1 v1 ... uk vk: Xiao Ming wants you to compute the number of fruits on several branches. A branch is a segment of a path from some node to the root. Each time Xiao Ming selects several branches and asks for the sum of the fruits on the nodes belonging to these branches. Note that branches may overlap; in that case the fruits on the overlapping part of the nodes are counted only once.

Input Format

The first line contains one integer nn (1≤n≤2×1051 \leq n\leq 2\times 10^5), the number of nodes.

The next n−1n - 1 lines each contain two numbers u,vu, v, indicating a direct edge between fruit uu and fruit vv. Nodes are numbered starting from 11.

Then one integer qq (1≤q≤2×1051\leq q\leq 2\times 10^5) follows, the number of events.

The last qq lines each begin with either 00 or 11.

  • If it is 00, this is event 00. The next two integers on this line are u,deltau, delta (1≤delta≤1091\leq delta\leq 10 ^ 9), meaning every node in the subtree rooted at uu grows deltadelta fruits.
  • If it is 11, this is event 11. The next integer on this line is kk (1≤k≤51\leq k \leq 5), the number of branches involved in this query, followed by kk pairs of integers uk,vku_k, v_k; each branch goes from node uku_k to node vkv_k.

Since the number of fruits may be very large, output the result modulo 2312^{31}.

Output Format

For each event 11, output the queried number of fruits.

Sample Input

5
1 2
2 3
2 4
1 5
3
0 1 1
0 2 3
1 2 3 1 1 4

Sample Output

13