East China University of Science and Technology Programming Contest 2026 Fall
A. Synecdoche, New York
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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:

  1. $$$T$$$ consists only of lowercase English letters.
  2. For every $$$i = 1, 2, \ldots, K$$$, the character of $$$T$$$ at position $$$p_i$$$ must equal the given character $$$c_i$$$, where $$$1 \le p_i \le L$$$ and $$$c_i$$$ is a lowercase letter.
  3. For every $$$i = 1, 2, \ldots, N$$$, the given string $$$s_i$$$ must not occur as a contiguous substring of $$$T$$$.

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$$$.

Input

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

Output one integer for each test case: the number of valid strings modulo $$$998\,244\,353$$$.

Examples
Input
3 1 1
2 b
ab
Output
650
Input
10 2 2
3 a
5 c
abc
dcabe
Output
113392371
Note

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.

B. AIMC Lab
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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:

  • For each integer pair $$$0 \le D \le 3$$$, $$$0 \le c \le 1$$$, qubit $$$P$$$ gains $$$A_{D,c}(x_P,y_P,z_P)$$$ energy if and only if:
    • The basis-state value of $$$P$$$ satisfies $$$c_P=c$$$.
    • For every qubit $$$Q$$$ with $$$d^2(P,Q)=D$$$, the value $$$c_P+c_Q+D$$$ is even.

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.

Input

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

Output one integer: the maximum total energy the system can achieve.

Examples
Input
1 1 1
3

5

100

200

1000

2000

50

60
Output
2265
Input
2 2 2
1 1
1 1

1 1
1 1

0 0
0 0

0 0
0 0

0 0
0 0

0 0
0 0

0 0
0 0

0 0
0 0

10 10
10 10

10 10
10 10

0 0
0 0

0 0
0 0

0 0
0 0

0 0
0 0

0 0
0 0

0 0
0 0
Output
88
Note

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$$$.

  • Each qubit gains $$$1$$$ energy from $$$A_{0,0}$$$, for a total of $$$8$$$.
  • All qubits at squared distance $$$2$$$ are also in state $$$|0\rangle$$$, so each qubit gains $$$10$$$ from $$$A_{2,0}$$$, for a total of $$$80$$$.

The total energy is $$$8+80=88$$$. This can be shown to be the maximum.

C. Split in Two 2
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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$$$.

Input

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$$$.

Output

For each test case, output one integer: the maximum possible value of $$$p$$$.

Example
Input
2
5 2
5 4 3 2 1
1 2 3 4 5
9 5
-1 1 -4 -5 -1 4 -1 -9 1
-9 -9 -8 2 4 -4 -3 -5 3
Output
5
-4
Note

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.

D. Unit Distance!?
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Construct a set of $$$n$$$ points in the Euclidean plane such that:

  • The absolute values of both coordinates of every point are at most $$$10^5$$$;
  • Each coordinate of every point becomes an integer when multiplied by $$$10^{13}$$$;
  • The distance between any two points is at least $$$10^{-4}$$$;
  • At least $$$\left\lfloor \frac12 n\log_2 n-n \right\rfloor$$$ distinct unordered pairs of points have distance in $$$[1-10^{-9},1+10^{-9}]$$$.
Input

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$$$.

Output

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.

Example
Input
1
3
Output
0 0
0 10000000000000
8660254037844 5000000000000
Note

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.

E. Eradication
time limit per test
4 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

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$$$.

Input

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.

Output

For each query, output one integer: $$$\sum_{i=l}^r f(i)$$$ modulo $$$998\,244\,353$$$.

Example
Input
4
432 432
1 10
10 15
1 100000000
Output
3
38
66
651260790
Note

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. $$$$$$

F. Convex Hull
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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

Input

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$$$.

Output

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.

Example
Input
5
2
-1 0 4
-1 4 -3
3
-1 100000 0
-1 202 10000
-2 400 19998
2
-1 2 0
-1 0 -1
2
-100000 0 100000
-1 0 4
2
-1 2 0
-1 4 -3
Output
NO
YES
NO
YES
NO
Note

Sample 1 Explanation

In the fourth test case, $$$x=0$$$ satisfies both inequalities, so an integer solution exists.

G. Beyond the Stars
time limit per test
8 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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.

  • Definition of an induced four-cycle: Choose $$$4$$$ vertices of $$$G$$$ that have exactly $$$4$$$ edges among them, forming a simple cycle. In particular, there are no diagonals.

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.

Input

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.

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.

Examples
Input
send
200000
2000 43600
29 1973
228 1127
...
92 573
Output
1 174 613 1323
1 955 1683 1755
...
1390 1615 1683 1777
Input
receive
2000 43600
29 1973
228 1127
...
92 573
800000
46 1297 1949
1056 1275 1454
...
387 1289 1533
Output
17713
191947
...
118231
Note

Parts of the sample are omitted because the complete data is too large.

H. Ordinary Offensive Magic
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Consider an $$$n \times m$$$ grid. Each cell has one of three states:

  1. / (forward-slash mirror): reflects on both sides. A ray turns $$$90^\circ$$$, connecting the top with the left and the bottom with the right.
  2. \ (backslash mirror): reflects on both sides. A ray turns $$$90^\circ$$$, connecting the top with the right and the bottom with the left.
  3. . (empty cell): contains no obstacle. A ray passes straight through, connecting the top with the bottom and the left with the right.

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.

Input

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:

  • Each of $$$d_1,d_2$$$ is one of U, D, L, R, denoting the top, bottom, left, or right boundary, respectively.
  • Each of $$$p_1,p_2$$$ is a positive integer specifying the midpoint of the outer edge of the $$$p$$$-th boundary cell. On U or D, $$$p$$$ is a column number ($$$1 \le p \le m$$$); on L or R, it is a row number ($$$1 \le p \le n$$$).

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$$$.

Output

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 \.

Example
Input
3
2 2
..
..
L 1 U 2
4 4
/\/\
/\/.
....
./..
L 2 L 4
4 4
/\/\
/\/.
..\/
./..
L 2 L 4
Output
./
..
/\/\
/\//
.//.
./..
IMPOSSIBLE
Note

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$$$.

I. Shooting Stars
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

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$$$:

  • You add its current energy to your total score.
  • If $$$i \gt 1$$$ and crystal $$$i-1$$$ has not yet been collected, its current energy changes sign.
  • If $$$i \lt n$$$ and crystal $$$i+1$$$ has not yet been collected, its current energy changes sign.

The crystals' numbers do not change as you collect them.

What is the maximum total score after collecting all $$$n$$$ crystals?

Input

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$$$.

Output

For each test case, output one integer: the maximum possible total score.

Example
Input
2
5
1 2 3 4 5
9
9 -9 8 -2 4 -4 3 -5 3
Output
15
47
Note

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.

J. Time Trouble 2
time limit per test
1 second
memory limit per test
1024 megabytes
input
standard input
output
standard output

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:

  1. For any $$$B \ge 60$$$, $$$A{:}B$$$ and $$$(A+1){:}(B-60)$$$ represent the same instant.
  2. For any $$$A \ge 24$$$, $$$A{:}B$$$ and $$$(A-24){:}B$$$ represent the same instant.

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.

Input

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$$$.

Output

For each test case, output two integers $$$h,m$$$ representing the equivalent standard time $$$h{:}m$$$.

Example
Input
5
7 110
25 30
0 0
23 59
100 200
Output
8 50
1 30
0 0
23 59
7 20
Note

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.

K. Aeonglass
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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.

Input

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$$$.

Output

For each test case, output one integer: the number of stable directions.

Example
Input
3
4
0 0
1 0
2 1
1 1
4
0 0
2 0
2 2
0 2
6
0 0
4 0
4 1
1 1
3 4
0 4
Output
3
4
1
Note

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.

L. In Filtration 3
time limit per test
2 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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?

Input

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.

Output

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.

Example
Input
3
3
0 0
0 1
0 2
4
0 0
1 0
2 0
3 0
8
2 0
0 1
1 1
2 1
1 2
2 2
3 2
1 3
Output
YES
NO
NO
Note

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.

M. Witch Trial
time limit per test
6 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

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:

  • $$$F$$$ is an ancestor of $$$x$$$, or $$$F=x$$$;
  • $$$F$$$ is an ancestor of $$$y$$$, or $$$F=y$$$;
  • $$$S = P(F,x)\cup P(F,y)$$$;

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.

Input

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:

  • If $$$\text{op}_i=1$$$, two integers $$$x,y$$$ ($$$1 \le x,y \le n$$$): perform Operation 1, swapping their weights.
  • If $$$\text{op}_i=2$$$, two integers $$$l,r$$$ ($$$1 \le l \lt r \le n$$$): perform Operation 2, reversing the weights in $$$[l,r]$$$.
  • If $$$\text{op}_i=3$$$, two integers $$$l,r$$$ ($$$1 \le l \le r \le n$$$): perform Operation 3, asking whether the vertices with weights in $$$[l,r]$$$ form a trident.

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$$$.

Output

For each Operation 3, output one line:

  • Output YES if $$$S=\{x\in N,\ 1\le x\le n\mid l\le a_x\le r\}$$$ is a trident;
  • Otherwise, output NO.

The answer is case-insensitive; for example, yes, YES, Yes, and YeS are all accepted as affirmative answers.

Example
Input
1
7 6
1 2
1 3
2 4
2 5
3 6
3 7
4 2 6 1 3 5 7
3 1 3
3 1 5
2 1 7
3 4 7
1 4 5
3 5 7
Output
YES
NO
YES
YES
Note

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:

  • Vertex $$$1$$$ is an ancestor of vertex $$$4$$$.
  • Vertex $$$1$$$ is an ancestor of vertex $$$5$$$.
  • $$$ P(1,4)\cup P(1,5) =\{1,2,4\}\cup\{1,2,5\}=S$$$。

Therefore, $$$S$$$ is a trident.