You are given a tree with vertices numbered . Initially, vertex has value .
Process queries in order. It is guaranteed that after each query, the graph is a tree.
0: remove the existing edge , and add the edge .1: update .2: for the current edge , regard as the parent side of . Output the sum of values of all vertices in the connected component containing after removing this edge.
Input
The input is given in the following format.
denote the -th edge of the initial tree. Each query is given in one of the three formats described in the statement.
Output
For each query of type 2, print the required sum of vertex values on a separate line.
Constraints
- .
- ().
- ().
- The initially given edges form a tree.
- In a query of type
0, the removed edge currently exists. - After each query of type
0, the graph is a tree. - In a query of type
1, and . - In a query of type
2, the edge currently exists.
Subtasks
Samples
입력
5 7
1 10 100 1000 10000
0 1
1 2
2 3
1 4
2 1 2
1 1 100000
2 1 2
0 1 2 2 0
2 0 2
0 2 3 3 1
2 1 4
출력
10011
110011
110011
101111
In the first query, with respect to edge , the component on the side of vertex contains vertices , so the sum is .
Then the value of vertex becomes , so the answer to the second query is .
The remaining answers are computed in the same way on the current tree.