Caden has come to understand "fate" in his own way. Leaving theater behind, he wants to use a string to represent his life through synecdoche. But in seeking a pure, original expression true to himself, he again falls into an infinite loop of self-reference. This time, Caden leaves the choice to you: portray his life for him.
Caden's synecdoche is a string $$$T$$$ of length $$$L$$$. We call $$$T$$$ valid if and only if all three conditions below hold:
Given $$$L$$$, $$$K$$$ position constraints $$$(p_i,c_i)$$$, and $$$N$$$ forbidden substrings $$$s_i$$$, count all valid strings $$$T$$$. Output the answer modulo $$$998\,244\,353$$$.
The first line contains three integers $$$L$$$, $$$K$$$, and $$$N$$$ ($$$1 \le L \le 10^{18}$$$, $$$0 \le K \le 500$$$, $$$0 \le N \le 50$$$): the string length, the number of position constraints, and the number of forbidden substrings.
Each of the next $$$K$$$ lines contains an integer $$$p_i$$$ and a lowercase letter $$$c_i$$$ ($$$1 \le p_i \le L$$$), describing a position constraint. All $$$p_i$$$ are distinct.
Each of the next $$$N$$$ lines contains a nonempty string $$$s_i$$$, describing a forbidden substring.
The sum of the lengths of all $$$s_i$$$ does not exceed $$$100$$$; that is, $$$\sum_{i=1}^N \vert{}s_i\vert{} \le 100$$$.
Output one integer for each test case: the number of valid strings modulo $$$998\,244\,353$$$.
3 1 12 bab
650
10 2 23 a5 cabcdcabe
113392371
Sample 1 Explanation
The string has length $$$3$$$, its second character must be b, and it must not contain ab. Valid strings have the form ?b?; the first character can be any lowercase letter except a. There are $$$25 \times 26 = 650$$$ such strings.
Your AIMC Lab has developed an entirely new three-dimensional quantum matrix!
Consider a three-dimensional grid of size $$$N \times M \times H$$$, with coordinates $$$1 \le x \le N$$$, $$$1 \le y \le M$$$, and $$$1 \le z \le H$$$. A qubit occupies every integer grid point. Let $$$(x_u,y_u,z_u)$$$ be the coordinates of qubit $$$u$$$.
For any two qubits $$$u$$$ and $$$v$$$, define their squared spatial distance as $$$$$$ d^2(u, v) = (x_u - x_v)^2 + (y_u - y_v)^2 + (z_u - z_v)^2. $$$$$$
The system has eight energy matrices $$$A_{D,c}$$$, each of size $$$N \times M \times H$$$, indexed by integers $$$0 \le D \le 3$$$ and $$$0 \le c \le 1$$$.
You may initialize each qubit to either basis state $$$|0\rangle$$$ or $$$|1\rangle$$$. Its corresponding basis-state value is $$$c_P=0$$$ or $$$c_P=1$$$.
After initialization, the total energy is calculated as follows:
As the chief scientist of AIMC Lab, initialize every qubit to a basis state so that the system's total energy is maximized. Output this maximum energy.
The first line contains three integers $$$N$$$, $$$M$$$, and $$$H$$$ ($$$1 \le N,M,H \le 100$$$ and $$$N \times M \times H \le 100$$$), the grid dimensions.
The data for the eight energy matrices $$$A_{D,c}$$$ follow in lexicographic order of $$$(D,c)$$$.
Each matrix consists of $$$N$$$ blocks. Each block has $$$M$$$ lines, each containing $$$H$$$ integers. Blocks are separated by blank lines.
The $$$z$$$-th number in the $$$y$$$-th line of the $$$x$$$-th block is the energy at $$$(x,y,z)$$$. All energy values satisfy $$$A_{D,c}(x_P,y_P,z_P) \in [0,10^9]$$$.
Output one integer: the maximum total energy the system can achieve.
1 1 135100200100020005060
2265
2 2 21 11 11 11 10 00 00 00 00 00 00 00 00 00 00 00 010 1010 1010 1010 100 00 00 00 00 00 00 00 00 00 00 00 0
88
Sample 1 Explanation
The grid contains only one qubit, at $$$(1,1,1)$$$.
Initializing it to $$$|1\rangle$$$ gives $$$A_{0,1}(1,1,1)+A_{1,1}(1,1,1)+A_{2,1}(1,1,1)+A_{3,1}(1,1,1)=5+200+2000+60=2265$$$, which is optimal.
Sample 2 Explanation
Initialize all $$$8$$$ qubits of the $$$2 \times 2 \times 2$$$ grid to $$$|0\rangle$$$.
The total energy is $$$8+80=88$$$. This can be shown to be the maximum.
You are given two arrays $$$a$$$ and $$$b$$$, each of length $$$n$$$.
Choose any $$$k \in [0,n]$$$ and concatenate the first $$$k$$$ elements of $$$a$$$ with the last $$$n-k$$$ elements of $$$b$$$ to form a new array of length $$$n$$$.
Select exactly $$$m$$$ pairwise nonadjacent elements from the new array. Let $$$p$$$ be the smallest selected element. Maximize $$$p$$$.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$), the number of test cases.
The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le m \le \lceil \frac n2 \rceil \le n \le 2 \times 10^5$$$): the array length and the number of elements to select.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$).
The third line contains $$$n$$$ integers $$$b_1,b_2,\ldots,b_n$$$ ($$$-10^9 \le b_i \le 10^9$$$).
The sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, output one integer: the maximum possible value of $$$p$$$.
25 25 4 3 2 11 2 3 4 59 5-1 1 -4 -5 -1 4 -1 -9 1-9 -9 -8 2 4 -4 -3 -5 3
5 -4
Sample 1 Explanation
In the first test case, choosing $$$k=4$$$ gives $$$[5,4,3,2,5]$$$. Select the first and fifth elements; their minimum is $$$5$$$, which is optimal.
Construct a set of $$$n$$$ points in the Euclidean plane such that:
The first line contains an integer $$$T$$$ ($$$1 \le T \le 100$$$), the number of test cases.
Each test case contains one integer $$$n$$$ ($$$2 \le n \le 5000$$$), the number of points to construct.
The sum of $$$n$$$ over all test cases does not exceed $$$5000$$$.
For each test case, output $$$n$$$ lines. The $$$i$$$-th line contains two integers $$$X_i,Y_i$$$ ($$$-10^{18} \le X_i,Y_i \le 10^{18}$$$), representing the actual point $$$\left(\frac{X_i}{10^{13}},\frac{Y_i}{10^{13}}\right)$$$.
Your output is accepted if and only if it satisfies this format and all four conditions above.
If several valid constructions exist, output any one of them.
13
0 00 100000000000008660254037844 5000000000000
Sample 1 Explanation
In the first test case, the actual coordinates are:
$$$$$$ (x_1, y_1) = (0, 0), (x_2, y_2) = (1, 0), (x_3, y_3) = (0.5, 0.8660254038) $$$$$$
The first three conditions are easy to verify. The pairwise distances are:
$$$$$$ d_{12} = 1, d_{13} = d_{23} = 1.000000000013476527219909191607\ldots = 1 + 1.3476 \times 10^{-11} $$$$$$ Thus every pairwise distance is within the allowed tolerance of $$$1$$$, satisfying the fourth condition.
We often simplify the square root of a large integer into radical form; for example, $$$\sqrt{432}=12\sqrt3$$$.
Define the number-theoretic function $$$f(n)=\min\{a \mid n=ab^2,\ a,b\in\mathbb N\}$$$ on $$$\mathbb N$$$. In other words, $$$f(n)$$$ is the smallest natural number $$$a$$$ satisfying the equation. Such an $$$a$$$ always exists.
You are given $$$q$$$ queries, each specifying $$$l$$$ and $$$r$$$. For each query, find $$$\sum_{i=l}^r f(i)$$$ modulo $$$998\,244\,353$$$.
The first line contains an integer $$$q$$$ ($$$1 \le q \le 500$$$), the number of queries.
Each of the next $$$q$$$ lines contains two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le 10^{12}$$$), specifying a query interval.
For each query, output one integer: $$$\sum_{i=l}^r f(i)$$$ modulo $$$998\,244\,353$$$.
4 432 432 1 10 10 15 1 100000000
3 38 66 651260790
Sample 1 Explanation
For the second and third queries, the corresponding values of $$$f$$$ are:
$$$$$$ \begin{array}{c|ccccccccccccccc} n &1&2&3&4&5&6&7&8&9&10&11&12&13&14&15\\ \hline f(n) &1&2&3&1&5&6&7&2&1&10&11&3&13&14&15 \end{array} $$$$$$
In particular, the third query gives $$$$$$ \sum_{i = 10}^{15}f(i) = f(10) + f(11) + f(12) + f(13) + f(14) + f(15) = 10 + 11 + 3 + 13 + 14 + 15 = 66. $$$$$$
You are given $$$n$$$ quadratic inequalities, each of the form
$$$$$$ a_i x^2 + b_i x + c_i \gt 0 $$$$$$
It is guaranteed that $$$a_i \lt 0$$$ for every $$$1 \le i \le n$$$.
Determine whether there is an integer $$$x$$$ satisfying all $$$n$$$ inequalities simultaneously.z
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$), the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \times 10^5$$$), the number of inequalities.
Each of the next $$$n$$$ lines contains three integers $$$a_i,b_i,c_i$$$ ($$$-10^5 \le a_i \le -1$$$, $$$-10^5 \le b_i,c_i \le 10^5$$$), the coefficients of the $$$i$$$-th inequality.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, output YES if such an integer $$$x$$$ exists, or NO otherwise.
The answer is case-insensitive; for example, yes, YES, Yes, and YeS are all accepted as affirmative answers.
52-1 0 4-1 4 -33-1 100000 0-1 202 10000-2 400 199982-1 2 0-1 0 -12-100000 0 100000-1 0 42-1 2 0-1 4 -3
NOYESNOYESNO
Sample 1 Explanation
In the fourth test case, $$$x=0$$$ satisfies both inequalities, so an integer solution exists.
This is a communication problem. Pay attention to its unusual constraints.
That was long ago, in a past forgotten by all of ECUST...
In that forgotten age, Zhulin and Qianwai fought side by side, lived together, and gazed up at the same stars. Later, sand buried their language, oceans severed their roads, and even their names faded from history. Only the vast, silent star chart above them remained: public, radiant, and unchanging. Yet nobody knew which stars they had once quietly joined into a message.
This problem has $$$20$$$ test cases.
You are given an undirected graph $$$G=(V,E)$$$ with $$$|V|=2000$$$ and $$$|E|=43\,600$$$. It has no multiple edges or self-loops and is generated as follows. Initially, $$$G$$$ has $$$|V|$$$ vertices and no edges. Then, $$$|E|$$$ times, the generator uniformly chooses one of the vertex pairs not yet joined by an edge and adds an undirected edge between them.
Your program will be run twice:
First run
In the first run, you play Zhulin. Choose and output $$$n$$$ induced four-cycles in $$$G$$$. They may share vertices.
Second run
In the second run, you play Qianwai. The judge has your complete output from the first run. For each of $$$q$$$ queries, it selects one of your four-cycles, deletes one of its vertices, and gives you the other three vertex numbers. Report the index of the four-cycle in Zhulin's output from which they came.
First run
The first line contains the string send.
The second line contains an integer $$$n$$$ ($$$n=200\,000$$$), the number of induced four-cycles you must output.
The third line contains two integers $$$|V|$$$ and $$$|E|$$$.
Each of the next $$$|E|$$$ lines contains two integers $$$u,v$$$, indicating an undirected edge between vertices $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le |V|$$$).
Second run
The first line contains the string receive.
The second line contains two integers $$$|V|$$$ and $$$|E|$$$.
Each of the next $$$|E|$$$ lines contains two integers $$$u,v$$$, indicating an undirected edge between vertices $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le |V|$$$).
Line $$$|E|+3$$$ contains an integer $$$q$$$ ($$$q=4n$$$), the number of received vertex sets.
Each of the next $$$q$$$ lines contains $$$3$$$ integers: the vertices remaining after the judge removes one vertex from a four-cycle in your first-run output.
First run
Output $$$n$$$ lines. Line $$$i$$$ contains four integers $$$v_1,v_2,v_3,v_4$$$, the vertices of the $$$i$$$-th induced four-cycle.
Second run
Output $$$q$$$ lines. For each received vertex set, output an integer $$$i$$$ ($$$1 \le i \le n$$$), the index of its four-cycle.
send 200000 2000 43600 29 1973 228 1127 ... 92 573
1 174 613 1323 1 955 1683 1755 ... 1390 1615 1683 1777
receive 2000 43600 29 1973 228 1127 ... 92 573 800000 46 1297 1949 1056 1275 1454 ... 387 1289 1533
17713 191947 ... 118231
Parts of the sample are omitted because the complete data is too large.
Consider an $$$n \times m$$$ grid. Each cell has one of three states:
Initially, some cells contain fixed / or \ mirrors; the rest are empty. You may leave each initially empty cell empty, replace it with a / mirror, or replace it with a \ mirror.
The outside boundary of the grid consists of $$$2(n+m)$$$ unit-length segments. A ray may enter or leave only perpendicularly through the midpoint of one of these segments.
Given an entry point and a target exit point, determine whether the grid can be filled legally so that a ray entering at the specified point, after straight-line travel and reflections, exits at exactly the target point.
If possible, output a valid completed grid that minimizes the number of cells traversed by the ray from the entry point to the target exit point. Count one traversal each time the ray enters a cell; repeated visits to the same cell are counted separately. If there are multiple optimal completions, output any of them. Otherwise, report that it is impossible.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 100$$$), the number of test cases.
The first line of each test case contains two integers $$$n,m$$$ ($$$1 \le n \times m \le 2 \times 10^5$$$), the numbers of rows and columns.
Each of the next $$$n$$$ lines contains a string of length $$$m$$$ describing the initial grid. Here / is a forward-slash mirror, \ is a backslash mirror, and . is an empty cell.
The next line contains four space-separated values $$$d_1,p_1,d_2,p_2$$$. The first pair specifies the entry point, and the second specifies the target exit point:
It is guaranteed that $$$(d_1,p_1) \ne (d_2,p_2)$$$.
The sum of $$$n \times m$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, if a valid completion exists, output $$$n$$$ lines of length $$$m$$$ describing it. Otherwise, output IMPOSSIBLE.
A backslash must usually be escaped: \\ outputs \.
32 2....L 1 U 24 4/\/\/\/....../..L 2 L 44 4/\/\/\/...\/./..L 2 L 4
./../\/\/\//.//../..IMPOSSIBLE
Sample 1 Explanation
In the first test case, the ray enters from the left edge of row $$$1$$$ and travels right. It passes through the empty cell $$$(1,1)$$$, turns upward at the / mirror in $$$(1,2)$$$, and exits through the top edge of column $$$2$$$.
There are $$$n$$$ crystals numbered $$$1$$$ through $$$n$$$ from left to right. Crystal $$$i$$$ initially contains $$$a_i$$$ units of energy. You may collect all $$$n$$$ crystals in any order.
When you collect crystal $$$i$$$:
The crystals' numbers do not change as you collect them.
What is the maximum total score after collecting all $$$n$$$ crystals?
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$), the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \times 10^5$$$), the number of crystals.
The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^9 \le a_i \le 10^9$$$), their initial energies.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$.
For each test case, output one integer: the maximum possible total score.
251 2 3 4 599 -9 8 -2 4 -4 3 -5 3
15 47
Sample 1 Explanation
In the first test case, collecting crystals in the order $$$3 \to 5 \to 1 \to 2 \to 4$$$ gives a score of $$$15$$$. This is optimal.
To prove that he is never late for class, Thirstarfish insists that he entered the classroom at $$$7{:}110$$$ for a class beginning at $$$8{:}00$$$. This inspires a "generalized time notation."
In generalized time notation, a time is written $$$A{:}B$$$, where $$$A,B$$$ are nonnegative integers.
We define two equivalence rules for generalized times:
A time $$$h{:}m$$$ is a "standard time" if and only if $$$0 \le h \lt 24$$$ and $$$0 \le m \lt 60$$$.
Given a generalized time, find the unique equivalent standard time.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^5$$$), the number of test cases.
Each test case contains two integers $$$A,B$$$ ($$$0 \le A,B \le 10^9$$$), representing the generalized time $$$A{:}B$$$.
For each test case, output two integers $$$h,m$$$ representing the equivalent standard time $$$h{:}m$$$.
57 11025 300 023 59100 200
8 501 300 023 597 20
Sample 1 Explanation
In the first test case, $$$7{:}110 \to 8{:}50$$$ by rule 1, since $$$110=60+50$$$.
In the second test case, $$$25{:}30 \to 1{:}30$$$ by rule 2, since $$$25=24+1$$$.
In the third test case, $$$0{:}0$$$ is already a standard time.
In the Euclidean plane, you are given a polygon $$$P=P_0P_1\cdots P_{n-1}$$$ whose vertices are listed in counterclockwise order.
An angle $$$\alpha$$$ ($$$0 \le \alpha \lt \pi$$$) is a stable direction if and only if there exists a $$$c \in R$$$ such that, for every point $$$X$$$ in polygon $$$P$$$ (including its boundary), the perpendicular segment from $$$X$$$ to the line $$$$$$ \cos \alpha\,x + \sin \alpha\,y + c = 0 $$$$$$ lies entirely in $$$P$$$ (including its boundary). Here $$$\alpha$$$ is a direction of the line's normal vector.
Find the number of stable directions. This number can be shown to be finite.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 100$$$), the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$3 \le n \le 10^5$$$), the number of polygon vertices.
Each of the next $$$n$$$ lines contains two integers $$$x_i,y_i$$$ ($$$-10^9 \le x_i,y_i \le 10^9$$$), the coordinates of the $$$i$$$-th vertex, listed in counterclockwise order.
Within a test case, all vertices are distinct. Adjacent edges intersect only at their shared endpoint, and nonadjacent edges do not intersect.
The sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.
For each test case, output one integer: the number of stable directions.
340 01 02 11 140 02 02 20 260 04 04 11 13 40 4
341

The lines and stable directions for test case 1 are
$$$$$$ \begin{aligned} L_1:\quad &x-1=0, &\alpha_1&=0,\\ L_2:\quad &\frac{\sqrt{2}}{2}x+\frac{\sqrt{2}}{2}y-\frac{3\sqrt{2}}{4}=0, &\alpha_2&=\frac{\pi}{4},\\ L_3:\quad &-\frac{1}{\sqrt{5}}x+\frac{2}{\sqrt{5}}y=0, &\alpha_3&=\pi-\arctan 2. \end{aligned} $$$$$$
The lines and stable directions for test case 2 are
$$$$$$ \begin{aligned} L_1:\quad &x-1=0, &\alpha_1&=0,\\ L_2:\quad &y-1=0, &\alpha_2&=\frac{\pi}{2},\\ L_3:\quad &\frac{\sqrt{2}}{2}x+\frac{\sqrt{2}}{2}y-\sqrt{2}=0, &\alpha_3&=\frac{\pi}{4},\\ L_4:\quad &-\frac{\sqrt{2}}{2}x+\frac{\sqrt{2}}{2}y=0, &\alpha_4&=\frac{3\pi}{4}. \end{aligned} $$$$$$
The line and stable direction for test case 3 are
$$$$$$ L:\quad x-\frac{1}{2}=0, \qquad \alpha_1=0. $$$$$$
The corresponding line is not uniquely determined.
Maddy is still purging Baddy's evil army... for the third time!
The game takes place on an infinite Cartesian plane, which you may imagine as an infinite chessboard. Baddy controls $$$n$$$ stationary cannons, placed at $$$(x_1,y_1),(x_2,y_2),\ldots,(x_n,y_n)$$$.
Under Chinese chess rules, a cannon attacks by jumping over a screen. If cannons $$$A$$$ and $$$B$$$ share a row or column and exactly one other cannon $$$C$$$ lies between them, $$$A$$$ attacks $$$B$$$ (and $$$B$$$ attacks $$$A$$$). Cannon $$$C$$$ is their "screen."
At each step, Maddy may destroy a cannon that is not currently attacked by any other cannon. The destroyed cannon is immediately removed; it can no longer attack or serve as a screen.
Maddy wants to destroy all $$$n$$$ cannons. Does there exist an order of destruction that clears the board?
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^5$$$), the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \times 10^5$$$), the number of cannons.
Each of the next $$$n$$$ lines contains two integers $$$x_i,y_i$$$ ($$$-10^9 \le x_i,y_i \le 10^9$$$), the position of cannon $$$i$$$.
The sum of $$$n$$$ over all test cases does not exceed $$$2 \times 10^5$$$. All cannon positions within a test case are distinct.
For each test case, output YES if some valid destruction order clears the board, or NO otherwise.
The answer is case-insensitive; for example, yes, YES, Yes, and YeS are all accepted as affirmative answers.
330 00 10 240 01 02 03 082 00 11 12 11 22 23 21 3
YESNONO
Sample 1 Explanation
In the first test case, the three cannons share a column. Initially, $$$(0,0)$$$ and $$$(0,2)$$$ attack each other over the screen at $$$(0,1)$$$, while $$$(0,1)$$$ is unattacked. Destroy $$$(0,1)$$$ first. Then the other two are unattacked and may be destroyed in either order.
In the second test case, four cannons share a row. Initially, $$$(0,0)$$$ and $$$(2,0)$$$ attack each other over $$$(1,0)$$$; $$$(1,0)$$$ and $$$(3,0)$$$ attack each other over $$$(2,0)$$$. Thus every cannon is attacked, none can be destroyed, and the answer is NO.
Your trident has struck a villager again. This time, when the trial ends, you discover that you can no longer find it.
You know that the trident landed on a rooted tree $$$T$$$ with $$$n$$$ vertices, rooted at vertex $$$1$$$. Each vertex has a weight $$$a_i$$$, and at every moment these weights form a permutation of $$$1 \sim n$$$. For vertices $$$u,v$$$, let $$$P(u,v)$$$ be their simple path, including both $$$u$$$ and $$$v$$$.
A set $$$S$$$ of tree vertices is a trident if and only if there exist three vertices $$$F,x,y$$$ (which may be equal) satisfying:
Process $$$q$$$ operations in order. There are three types:
Operation 1: Lightning. Given vertices $$$x$$$ and $$$y$$$, swap their current weights.
Operation 2: Judgment. Given two distinct weights $$$l \lt r$$$, reverse the weights within $$$[l,r]$$$.
Formally, if vertex $$$x$$$ has weight $$$a_x$$$ before this operation and $$$a'_x$$$ afterward, define $$$$$$ a'_x= \begin{cases} l+r-a_x, & l\le a_x\le r,\\ a_x, & \text{otherwise}. \end{cases} $$$$$$
Then set $$$a_x\leftarrow a'_x$$$ simultaneously for every integer $$$1 \le x \le n$$$. The weights remain a permutation of $$$1 \sim n$$$.
Operation 3: Find the trident. Given $$$l \le r$$$, determine whether $$$S=\{x\in N,\ 1\le x\le n\mid l\le a_x\le r\}$$$ is a trident.
Answer all questions from Operation 3 in order.
The first line contains an integer $$$T$$$ ($$$1 \le T \le 10^3$$$), the number of test cases.
The first line of each test case contains two integers $$$n,q$$$ ($$$1 \le n,q \le 10^5$$$), the numbers of tree vertices and operations.
Each of the next $$$n-1$$$ lines contains two integers $$$u,v$$$ ($$$1 \le u,v \le n$$$, $$$u\ne v$$$), describing a tree edge.
The next line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1 \le a_i \le n$$$), the initial vertex weights.
Each of the next $$$q$$$ lines describes an operation. It starts with an integer $$$\text{op}_i$$$ ($$$1 \le \text{op}_i \le 3$$$), followed by:
Within each test case, the initial weights form a permutation of $$$1\sim n$$$, and the given edges form a tree with $$$n$$$ vertices.
Across all test cases, $$$\sum n \le 3 \times 10^5$$$ and $$$\sum q \le 3 \times 10^5$$$.
For each Operation 3, output one line:
The answer is case-insensitive; for example, yes, YES, Yes, and YeS are all accepted as affirmative answers.
17 61 21 32 42 53 63 74 2 6 1 3 5 73 1 33 1 52 1 73 4 71 4 53 5 7
YESNOYESYES

For the third trident query in the first test case, after the preceding Judgment operation, the current weights are $$$$$$ (a_1,a_2,\ldots,a_7)=(4,6,2,7,5,3,1). $$$$$$
Weights $$$4,5,6,7$$$ are at vertices $$$1,5,2,4$$$, respectively, so $$$S=\{1,2,4,5\}$$$.
Choose $$$F=1$$$, $$$x=4$$$, and $$$y=5$$$. Then:
Therefore, $$$S$$$ is a trident.