You are given a tree with vertices numbered from to . Every vertex is colored either black or white.
is a binary tree. Initially, the root of is vertex .
Process the following queries.
1: Change the root of to vertex .2: Toggle the color of vertex . White becomes black, and black becomes white.3: Let be the number of white vertices in the subtree rooted at vertex with respect to the current root. Let be the number of white vertices on the path from vertex to the current root. Both endpoints belong to the path. Print .
It is guaranteed that is a binary tree regardless of which vertex is chosen as the root.
Input
The input is given from Standard Input in the following format:
case case case
Each case is given in the following format:
If , vertex is black. If , vertex is white.
The -th edge connects vertices and .
Each has one of the forms 1 , 2 , and 3 .
Output
For every type 3 query, print the answer on its own line.
Constraints
- .
- .
- .
- ().
- ().
- The given edges form a tree.
- The given tree is binary regardless of which vertex is chosen as the root.
- Every query satisfies .
- Every case contains at least one type
3query. - The sum of over all cases does not exceed .
- The sum of over all cases does not exceed .
Subtasks
Samples
In the third type 3 query of the first case, vertices belong to the subtree, while vertices belong to the path to the root. The two white-vertex counts are and , so the answer is .
The second case has only one vertex, so every type 3 query has answer .