You are given a tree with vertices. Each leaf (that is, a vertex of degree ) has a status: active or inactive. Initially, all leaves are inactive.
There are queries of two types:
1 v — change the status of leaf to the opposite one (active inactive). It is guaranteed that is a leaf (a vertex of degree ).
2 s — determine who wins the game described below, if the token is initially placed at vertex . It is guaranteed that is not a leaf (a vertex of degree ).
Game: there is a token initially placed at vertex . Two players take turns, with the first player moving first. On each move, a player moves the token to an unvisited adjacent vertex. The game ends when the token is at a vertex from which it cannot move anywhere (that is, all adjacent vertices have already been visited — this is necessarily a leaf of the graph). The second player wins if the token ends its move at an active vertex; otherwise, the first player wins.
Online mode. If the input parameter m = 1, then in each query the actual vertex number is replaced by an encrypted number.
Consider a query of one of the two types:
1 x — an encrypted query to change the status of a leaf;
2 x — an encrypted query for a game from some starting vertex.
Let be a counter, initially equal to . For each query, the number is decrypted into the actual vertex number by the formula
That is:
in query 1 x, you need to change the status of leaf ;
in query 2 x, the game starts at vertex .
After each query, the counter is updated:
after query 1 x with decrypted leaf : \mathit{acc} = (\mathit{acc} + v) \bmod n;
after query 2 x with answer w \in \{1, 2\}: \mathit{acc} = (\mathit{acc} + w) \bmod n.
If m = 0, then the queries are not encrypted. In that case, in query 1 v the number is the leaf whose status must be changed, and in query 2 v the number is the starting vertex of the game.
The first line contains three integers , , and (3 \le n \le 5 \cdot 10^5, 1 \le q \le 5 \cdot 10^5, m \in \{0, 1\}).
The next n - 1 lines contain the edges of the tree: two integers u_i and v_i each (1 \le u_i, v_i \le n, u_i \ne v_i).
The next lines contain the queries: type t \in \{1, 2\} and argument (1 \le x \le n). If m = 1, then is an encrypted value.
For each query of the second type, output one number in a separate line: if the first player wins, or if the second player wins.
Example 1
Example 2
Example 3
In the first example, the tree is a star with vertex in the center and leaves . Initially all leaves are inactive: for query 2 1, the first player makes the only move to any leaf, and the token stops at an inactive leaf — the first player wins, so the answer is . After three queries of type 1 that activate all leaves, for the repeated query 2 1, no matter where the first player moves, the token ends at an active leaf — the second player wins, so the answer is .
In the second example, the tree has a Y shape: vertex is connected to vertices , , and to vertex , which has leaf attached to it. Query 2 3 means that the tree is rooted at vertex . Before activating any leaves, the first player can reach an inactive leaf from vertex in one move (for example, to ) — answer . After activating leaves , , and , all three possible paths from end at an active leaf, so the first player cannot avoid losing — answer .
The third example demonstrates the online mode (m = 1) on the same tree as in the first example. The initial value is \mathit{acc} = 0, so the first encrypted query 2 1 is decoded as 2 1 and gives answer , after which \mathit{acc} = 1. The next encrypted query 1 1 is decoded as 1 2 (because ((1 - 1 + 1) \bmod 4) + 1 = 2), activating leaf , and then \mathit{acc} = (1 + 2) \bmod 4 = 3. Similarly, 1 4 is decoded as 1 3 (activating leaf , \mathit{acc} = 2), and 1 2 — as 1 4 (activating leaf , \mathit{acc} = 2). The last encrypted query 2 3 is decoded as 2 1 and returns .
( points): n, q \le 1000, m = 0;
( points): a leaf never changes its status from active to inactive, s = 1, m = 0;
( points): a leaf never changes its status from active to inactive, the token is initially at vertex in every query, m = 1;
( points): m = 0, there exists an integer k \ge 1 such that n = 2^k - 1, and the tree edges are of the form (i, \lfloor i / 2 \rfloor) for all 2 \le i \le n.
( points): only vertex has degree greater than , m = 0;
( points): s = 1, m = 0;
( points): n \le 10^5, m = 0;
( points): no additional constraints.