H. Views Testing
time limit per test
6 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

In the Odoo interface, you realize that it's all about views and smart buttons. Let's consider that Odoo has N distinct views and for each view, there are some smart buttons to take you to other views.

It's guaranteed that :

  • From every view, you can go to any other view using a series of clicks on smart buttons.
  • If there is a button that takes you from view $$$V_{1}$$$ to view $$$V_{2}$$$ , then there is a button that takes you from $$$V_{2}$$$ to $$$V_{1}$$$.
  • There is only one way to go from any view to any other view using the minimum number of clicks. (the views construct a tree like structure).

Since views are a very important part of Odoo, they should be tested carefully. That's where the Odoo tour test comes into play. The developers at Odoo developed an automatic testing program which will run infinitely. The test consists of a cyclic list of views of size $$$k$$$ (not necessarily distinct). At the start, the program starts from a view at some position $$$p$$$ in the list, then he goes to the next view at position $$$p+1$$$ using the minimum number of clicks, then to the view at position $$$p+2$$$ and so on (the view at position $$$1$$$ comes after the view at position $$$k$$$). A view is called tested if it is visited at least one time at some point during the test. You realized that some views might not get tested, so you introduced some updates to the original list of views and some other queries to collect analytics. The queries go as follows:

  • $$$1$$$ $$$p$$$ $$$u$$$: update the view at position $$$p$$$ by view with id $$$u$$$
  • $$$2$$$ $$$p$$$ $$$u$$$: find the minimum number of clicks needed for the view with id $$$u$$$ to be tested for the first time if the program starts running from position $$$p$$$ , print $$$-1$$$ if it's impossible to test that view.
Input

The first line of the input contains $$$2$$$ integers $$$n$$$ and $$$k$$$ $$$(1\leq n\leq 10^{5}, 1 \leq k \leq 10^{5})$$$, the number of views and the size of the list of views of the test.

The second line contains $$$k$$$ integers $$$v_{i}$$$ $$$(1\leq v_{i} \leq n)$$$, the ids of the views in the list of the test.

The next $$$n-1$$$ lines each contain $$$2$$$ integers $$$u$$$ and $$$v$$$ $$$(1\leq u, v \leq n, u \ne v)$$$, which means that views with id $$$u$$$ and $$$v$$$ have a smart button that connects them.

The next line contains an integer $$$q$$$ $$$(1\leq q\leq 10^{5})$$$, the number of queries to process.

The next $$$q$$$ lines each contain $$$3$$$ integers $$$t$$$, $$$p$$$, and $$$u$$$ $$$(1\leq t\leq 2, 1\leq p \leq k, 1\leq u\leq n)$$$, the description of the query.

Output

Print the answer for each query of the type $$$2$$$ in separate lines. It's guaranteed that there is at least one query of type $$$2$$$.

Example
Input
9 4
4 6 8 9
1 2
2 3
3 4
4 5
2 6
2 7
6 8
4 9
8
2 2 9
2 1 7
2 4 8
2 4 9
2 1 9
2 2 2
1 3 1
2 2 2
Output
6
-1
5
0
9
3
1