Maximum edge cost on a tree path

No attempts yetTime limit2sMemory limit512 MB

Problem

You are given a tree with NN vertices. A tree is a connected undirected graph with no cycle. The vertices are numbered 1 to NN, the edges are numbered 1 to N1N-1, and every edge has one cost.

Write a program that handles the following two queries.

  • 1 i c: change the cost of edge ii to cc.
  • 2 u v: print the largest cost among the edges on the simple path from uu to vv.

In a tree there is exactly one simple path between two different vertices.

Input

The first line contains the number of vertices NN (2N1000002 \le N \le 100\,000).

Each of the next N1N-1 lines describes one edge. The ii-th of those lines contains the two vertex numbers uu and vv joined by edge ii and the cost ww of that edge (1w10000001 \le w \le 1\,000\,000).

The next line contains the number of queries MM (1M1000001 \le M \le 100\,000).

Each of the next MM lines contains one query. A query of type 1 satisfies 1iN11 \le i \le N-1 and 1c10000001 \le c \le 1\,000\,000. A query of type 2 satisfies 1u,vN1 \le u, v \le N, and uu differs from vv.

Output

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