First black vertex on a path

Flip vertex colors and, along the root-to-v path, report the first black vertex encountered from the root.

Medium7TreeSegment treeDFSNo attempts yetTime limit2sMemory limit512 MB

Problem

You have a tree with NN vertices. A tree is a connected undirected graph with no cycle. The vertices are numbered 1 to NN, and every vertex starts out white.

Write a program that processes the following two queries in the order they are given.

  • 1 i: flip the colour of vertex ii. White becomes black, and black becomes white.
  • 2 v: walk the path from vertex 1 to vertex vv, starting at vertex 1, and print the number of the first black vertex you meet. If the path holds no black vertex, print -1.

The path includes vertex 1 and vertex vv. A tree has exactly one path between two vertices, so each query has a single answer.

Input

The first line has the number of vertices NN. (2N1000002 \le N \le 100000)

Each of the next N1N-1 lines has the numbers uu and vv of the two vertices joined by one edge. (1u,vN1 \le u, v \le N, uvu \ne v) The N1N-1 edges always form a tree.

The next line has the number of queries MM. (1M1000001 \le M \le 100000)

Each of the next MM lines has one query, either 1 i or 2 v. (1i,vN1 \le i, v \le N)

Output

For each query of type 2, print its answer on one line, in the order the queries are given.