You are given a tree with $$$n$$$ vertices numbered from $$$1$$$ to $$$n$$$. A slime occupies exactly $$$m$$$ vertices of the tree. It is guaranteed that the subgraph induced by the occupied vertices is connected.
Initially, the slime occupies vertices $$$s_1,s_2,\ldots,s_m$$$.
First, we define a function $$$f$$$ on a sequence of vertices. Consider a sequence $$$a_1,a_2,\ldots,a_k$$$. There are $$$k$$$ pieces of food. For each $$$i$$$, the $$$i$$$-th piece of food is located at vertex $$$a_i$$$. At first, only the first piece of food appears.
The slime may perform the following operations any number of times:
Formally, let $$$S$$$ be the current set of occupied vertices. Choose a vertex $$$u\in S$$$ and a vertex $$$v\notin S$$$, and replace $$$S$$$ with $$$(S\setminus{u})\cup{v}$$$. After the operation, the subgraph induced by $$$S$$$ must still be connected.
Define $$$f([a_1,a_2,\ldots,a_k])$$$ as the minimum number of Move operations needed for the slime to eat all $$$k$$$ pieces of food in order, starting from the initial occupied vertices $$$s_1,s_2,\ldots,s_m$$$.
There are $$$q$$$ queries. The input is forced online. The input gives encoded values $$$p_1,p_2,\ldots,p_q$$$. Let $$$\mathrm{ans}_0=0$$$. For each $$$i=1,2,\ldots,q$$$, the actual vertex of the $$$i$$$-th query is $$$c_i=((p_i-1+\mathrm{ans}_{i-1}) \bmod n)+1$$$, where $$$\mathrm{ans}_i=f([c_1,c_2,\ldots,c_i])$$$.
For each $$$i=1,2,\ldots,q$$$, output $$$\mathrm{ans}_i$$$.
Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The description of the test cases follows.
The first line of each test case contains three integers $$$n$$$, $$$m$$$, and $$$q$$$ ($$$2\le m\le n\le 10^5$$$, $$$1\le q\le 10^5$$$) — the number of vertices in the tree, the number of vertices occupied by the slime, and the number of queries.
Each of the next $$$n-1$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1\le u,v\le n$$$, $$$u\ne v$$$), denoting an edge of the tree.
The next line contains $$$m$$$ distinct integers $$$s_1,s_2,\ldots,s_m$$$ ($$$1\le s_i\le n$$$) — the vertices initially occupied by the slime. It is guaranteed that these vertices induce a connected subgraph.
The next line contains $$$q$$$ integers $$$p_1,p_2,\ldots,p_q$$$ ($$$1\le p_i\le n$$$) — the encoded query vertices.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
It is guaranteed that the sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output $$$q$$$ integers. The $$$i$$$-th integer should be $$$\mathrm{ans}_i$$$.
105 2 33 52 14 33 21 21 4 36 3 45 11 36 14 12 11 2 35 2 5 67 3 53 74 21 32 16 35 21 2 47 3 2 5 25 2 53 11 52 14 11 23 3 3 4 26 3 64 63 21 25 42 42 4 56 6 1 2 4 67 4 55 23 12 13 76 34 21 2 3 47 4 4 5 14 3 43 11 42 11 2 34 1 2 36 2 52 45 42 16 43 21 26 1 1 1 27 2 52 47 33 61 31 25 21 24 6 1 6 58 4 65 23 27 54 38 71 26 52 3 4 58 7 3 3 7 8
0 2 31 1 2 32 4 6 8 91 2 3 4 41 2 3 4 4 41 2 3 3 41 1 2 22 4 6 8 91 4 7 10 112 3 4 4 5 5
In the explanations below, the underlined vertex is the newly occupied vertex after a Move, and vertices where the slime eats food are written in bold.
In the first test case, after decoding, the food appears at vertices $$$1,4,5$$$ in order. Initially, the slime occupies $$$[1,2]$$$.
In the second test case, after decoding, the food appears at vertices $$$5,3,6,2$$$ in order. Initially, the slime occupies $$$[1,2,3]$$$.
In the third test case, after decoding, the food appears at vertices $$$7,5,6,4,3$$$ in order. Initially, the slime occupies $$$[1,2,4]$$$.
In the fourth test case, after decoding, the food appears at vertices $$$3,4,5,2,1$$$.
In the fifth test case, after decoding, the food appears at vertices $$$6,1,3,5,2,4$$$.
In the sixth test case, after decoding, the food appears at vertices $$$7,5,6,1,4$$$.