The 2025 ICPC Asia EC Regionals Online Contest (II)
A. Angry Birds
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Aris is playing the classic game, Angry Birds!

Because Aris has been playing for too long, Yuuka confiscated Aris's game console and demanded that Aris complete today's math homework before getting it back.

However, Sensei did not assign any math homework to Aris today, so Yuuka had to come up with a problem for Aris to solve.

Consider the game field of Angry Birds as a three-dimensional Euclidean space, and the bird as a sphere with radius $$$ R_3 $$$. Establish a spatial Cartesian coordinate system $$$ O-xyz $$$, such that the trajectory of the bird's center lies in the horizontal plane $$$ z=0 $$$.

It is known that the trajectory of the bird's center is a closed polyline, consisting of $$$ n $$$ segments connected end to end. The connection points are $$$ n $$$ points: $$$ (x_1, y_1, 0), (x_2, y_2, 0), \cdots, (x_n, y_n, 0) $$$. The $$$ i $$$-th segment has endpoints $$$ (x_i, y_i, 0) $$$ and $$$ (x_{i \bmod n + 1}, y_{i \bmod n + 1}, 0) $$$. However, due to sensor errors, the actual $$$ n $$$ points may deviate from $$$ (x_i, y_i, 0) $$$ by a distance not exceeding $$$ R_2 $$$ (the sensor deviation $$$ R_2 $$$ is the same for all points). That is, the actual $$$ i $$$-th point $$$ (x'_i, y'_i, 0) $$$ can be anywhere within the circle (which is still contained in the plane $$$ z=0 $$$) centered at $$$ (x_i, y_i, 0) $$$ with radius $$$ R_2 $$$.

Let $$$ S $$$ be the set of all points that the entire bird may pass through, i.e., points in 3D space whose distance to the bird's center trajectory is at most $$$ R_3 $$$. Yuuka requires Aris to compute the volume of the convex hull of $$$ S $$$.

Convex hull: The convex hull of a point set $$$ S $$$ is defined as the smallest set $$$ T $$$ such that for any two points in $$$ S $$$, all points on the line segment between them are contained in $$$ T $$$.

Input

The first line contains a positive integer $$$ T $$$ $$$( 1 \leq T \leq 10^3 )$$$, indicating the number of test cases.

For each test case, the first line contains three integers $$$n,R_2,R_3$$$ $$$(1\leq n\leq 10^5, 0\leq R_2,R_3\leq 10^6)$$$, representing the number of connection points, the sensor error radius, and the bird radius, respectively.

The next $$$ n $$$ lines each contain two integers $$$ x_i, y_i $$$ $$$( |x_i|, |y_i| \leq 10^6 )$$$, representing the $$$ i $$$-th connection point of the trajectory.

It is guaranteed that the sum of $$$ n $$$ over all test cases in a single test point does not exceed $$$ 10^5 $$$.

Output

For each test case, output a single floating-point number representing the answer. Your answer is considered correct if the relative or absolute error compared to the standard answer is at most $$$ 10^{-9} $$$.

Let your answer be $$$ a $$$ and the standard answer be $$$ b $$$. If $$$ \frac{|a - b|}{\max\{b, 1\}} \leq 10^{-9} $$$, it is considered correct.

Example
Input
1
5 1 1
0 0
3 1
2 3
2 2
-1 3
Output
77.622211120429589
Note

The convex hull of all points that the bird's center may pass through:

B. Rectangular Wooden Block
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Mr. Noya has a pet hamster that loves to gnaw on wood.

One day, Mr. Noya brought home a rectangular wooden block with dimensions $$$L \times W \times H$$$, meaning it has a length of $$$L$$$ units, a width of $$$W$$$ units, and a height of $$$H$$$ units, divided into $$$L \times W \times H$$$ unit cubes. Using one vertex of the block as the origin, the length direction as the $$$x$$$-axis, the width direction as the $$$y$$$-axis, and the height direction as the $$$z$$$-axis, a spatial coordinate system $$$O-xyz$$$ is established. The unit cube with $$$x$$$-coordinate in $$$[i-1, i)$$$, $$$y$$$-coordinate in $$$[j-1, j)$$$, and $$$z$$$-coordinate in $$$[k-1, k)$$$ is denoted as $$$(i, j, k)$$$.

Note: The block does not necessarily have length greater than width (i.e., it is not required that $$$W \leq L$$$); the terms are just used to fix the directions.

Mr. Noya does not want the wooden block to be completely gnawed away by his hamster, so he decides to reinforce it. Reinforcing the unit cube at $$$(i,j,k)$$$ has a cost $$$V(i,j,k)$$$. Additionally, there are three matrices $$$A,B,C$$$ representing constraints from the three orthogonal views (front view, side view, and top view):

  • For matrix $$$A = \{a_{ij}\}_{H \times L}$$$, if $$$a_{ij} = 0$$$, then for all $$$1 \leq p \leq W$$$, the cube at $$$(j, p, i)$$$ must not be reinforced. If $$$a_{ij} = 1$$$, at least one of these cubes must be reinforced.
  • For matrix $$$B = \{b_{ij}\}_{H \times W}$$$, if $$$b_{ij} = 0$$$, then for all $$$1 \leq q \leq L$$$, the cube at $$$(q, j, i)$$$ must not be reinforced. If $$$b_{ij} = 1$$$, at least one of these cubes must be reinforced.
  • For matrix $$$C = \{c_{ij}\}_{W \times L}$$$, if $$$c_{ij} = 0$$$, then for all $$$1 \leq r \leq H$$$, the cube at $$$(j, i, r)$$$ must not be reinforced. If $$$c_{ij} = 1$$$, any number (including zero) of these cubes may be reinforced.

Note: Mr. Noya can reinforce each unit cube at most once.

Note: For matrix $$$C$$$, a non-zero value does not require reinforcing at least one unit cube.

Under the above conditions, Mr. Noya wants to minimize the total cost of reinforcing the wooden block. Can you help him?

Note: You do not need to consider the issue of unit cubes being suspended in air.

Input

The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 5 \times 10^3)$$$, indicating the number of test cases.

For each test case, the first line contains three positive integers $$$L$$$, $$$W$$$, $$$H$$$ $$$(1 \leq L \times W \times H \leq 10^3)$$$, representing the length, width, and height of the block.

The next line contains $$$L\times W\times H$$$ integers. The $$$[(i-1)\times W+j-1]\times H+k$$$-th integer is $$$V(i,j,k)$$$ $$$(-10^9\leq V(i,j,k)\leq 10^9)$$$.

Then follow $$$H$$$ lines. The $$$i$$$-th line is a binary string of length $$$L$$$, denoted $$$a_{i1}a_{i2}\cdots a_{iL}$$$, representing the $$$i$$$-th row of matrix $$$A$$$.

Then follow $$$H$$$ lines. The $$$i$$$-th line is a binary string of length $$$W$$$, denoted $$$b_{i1}b_{i2}\cdots b_{iW}$$$, representing the $$$i$$$-th row of matrix $$$B$$$.

Then follow $$$W$$$ lines. The $$$i$$$-th line is a binary string of length $$$L$$$, denoted $$$c_{i1}c_{i2}\cdots c_{iL}$$$, representing the $$$i$$$-th row of matrix $$$C$$$.

It is guaranteed that the sum of $$$L \times W \times H$$$ over all test cases in a single test point does not exceed $$$5 \times 10^3$$$.

Output

For each test case, the first line contains a string $$$\texttt{YES}$$$ or $$$\texttt{NO}$$$ indicating whether Mr. Noya's conditions can be satisfied.

If the conditions can be satisfied, then output on the second line an integer representing the minimum reinforcement cost of the cuboid; on the third line a nonnegative integer representing the number $$$k$$$ of reinforced unit cubes; followed by $$$k$$$ lines, each containing three positive integers representing the coordinates of each reinforced unit cube. Note that each unit cube can be reinforced at most once.

If there are multiple valid solutions, outputting any one of them will be considered correct.

Example
Input
2
3 2 2
1 1 4 5 -1 4 -1 9 1 9 8 1
011
111
11
11
111
111
1 2 2
1 2 3 4
0
0
01
01
1
1
Output
YES
5
6
2 1 1
2 2 1
3 1 1
1 1 2
2 1 2
3 2 2
NO

C. Jiaxun!
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are three students training hard for ICPC. They are practicing on a problemset consisting of exactly $$$S$$$ problems. Each problem belongs to exactly one of the following seven categories, describing which subset of students can solve it:

  • $$$F_1$$$: only student $$$1$$$ can solve;
  • $$$F_2$$$: only student $$$2$$$ can solve;
  • $$$F_3$$$: students $$$1$$$ and $$$2$$$ (but not $$$3$$$) can solve;
  • $$$F_4$$$: only student $$$3$$$ can solve;
  • $$$F_5$$$: students $$$1$$$ and $$$3$$$ (but not $$$2$$$) can solve;
  • $$$F_6$$$: students $$$2$$$ and $$$3$$$ (but not $$$1$$$) can solve;
  • $$$F_7$$$: students $$$1$$$, $$$2$$$ and $$$3$$$ can all solve.

It is guaranteed that $$$$$$ F_1 + F_2 + F_3 + F_4 + F_5 + F_6 + F_7 = S. $$$$$$

You are going to assign each problem to exactly one student who can solve it. Your goal is to make the training as balanced as possible: maximize the minimum number of problems solved by any single student. Output this maximum possible value.

Input

The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 10^5$$$)— the number of test cases.

For each test case, the first line contains a single integer $$$S$$$ ($$$0 \leq S \leq 7 \times 10^8$$$).

The second line contains seven non-negative integers $$$F_1, F_2, F_3, F_4, F_5, F_6, F_7$$$ ($$$0 \le F_1, \cdots, F_7 \le 10^{8}$$$).

It is guaranteed that $$$F_1 + \cdots + F_7 = S$$$.

Output

For each test case, print a single integer — the maximum possible value of the minimum solved-count among the three students after assigning all $$$S$$$ problems.

Example
Input
4
36
14 4 3 2 9 0 4
41
4 8 4 4 3 14 4
53
3 0 12 6 14 11 7
55
11 10 11 10 2 8 3
Output
11
13
17
18

D. Arcane Behemoths
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have $$$N$$$ Arcane Behemoths, each with an attack value $$$A_i$$$.

You may choose any non-empty subsequence of Behemoths and sell them one by one. Whenever you sell a Behemoth, each remaining unsold Behemoth in the subsequence increases its attack value by the attack value of the Behemoth you just sold.

The value of a subsequence is the maximum attack value the last remaining Behemoth can achieve, if the other Behemoths in the subsequence are sold in an optimal order.

Your task is to compute the sum of values over all non-empty subsequences of the sequence. Print the result modulo $$$998244353$$$.

Input

The first line contains a single integer $$$T$$$ ($$$1 \leq T \leq 2 \times 10^5$$$) — the number of test cases.

For each test case, the first line contains an integer $$$N$$$ ($$$1 \leq N \leq 2 \times 10^5$$$) — the number of Behemoths.

The second line contains $$$N$$$ integers $$$A_1, A_2, \ldots, A_N$$$ $$$(0 \leq A_i \lt 998244353)$$$ — the initial attack values of the Behemoths.

It is guaranteed that $$$\sum N \leq 2\times 10^5$$$ over all test cases.

Output

For each test case, print a single integer — the sum of values over all non-empty subsequences modulo $$$998244353$$$.

Example
Input
3
3
1 2 3
6
1 1 4 5 1 4
3
998244350 998244351 998244352
Output
27
1266
998244328
Note

Consider the subsequences of $$$[1,2,3]$$$:

  • $$$[1]$$$ → only one Behemoth remains, value = $$$1$$$.
  • $$$[2]$$$ → value = $$$2$$$.
  • $$$[3]$$$ → value = $$$3$$$.
  • $$$[1,2]$$$: sell the larger Behemoth $$$2$$$ first, leave $$$1$$$ → final attack = $$$1+2=3$$$.
  • $$$[1,3]$$$: sell $$$3$$$ first, leave $$$1$$$ → final attack = $$$1+3=4$$$.
  • $$$[2,3]$$$: sell $$$3$$$ first, leave $$$2$$$ → final attack = $$$2+3=5$$$.
  • $$$[1,2,3]$$$:
    • Step 1: sell $$$3$$$ → remaining sequence $$$[1+3,2+3] = [4,5]$$$.
    • Step 2: sell $$$2$$$ (now $$$5$$$) → add its attack to remaining $$$4$$$, final attack = $$$4+5=9$$$.
    • Thus, the value of this subsequence is $$$9$$$.

Finally, summing all values: $$$1+2+3+3+4+5+9 = 27$$$.

E. Zero
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

An integer sequence $$$a_1,a_2,\cdots,a_n$$$ is called a zero sequence if and only if it satisfies the following conditions:

  • For $$$i=1,2,\cdots,n-1$$$, $$$a_i \neq a_{i+1}$$$.
  • The binary XOR sum of $$$a_1,a_2,\cdots,a_n$$$ is $$$0$$$, i.e., $$$$$$ \bigoplus_{i=1}^{n}a_i=0 $$$$$$

Given $$$n$$$ and $$$m$$$, find the number of zero sequences of length $$$n$$$ where each element is chosen from the set $$$\{0,1,2,\cdots,2^m-1\}$$$.

Input

The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 10^4)$$$, indicating the number of test cases.

For each test case, one line contains two integers $$$n,m$$$ $$$(1\leq n\leq 10^9,0\leq m\leq 10^9)$$$, representing the length of the sequence and the binary length of the sequence elements, respectively.

Output

For each test case, output one integer representing the answer modulo $$$998244353$$$.

Example
Input
5
1 3
2 3
3 3
4 3
5 3
Output
1
0
49
392
2401

F. Square Permutation I
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Give two permutations $$$p$$$ and $$$q$$$ of length $$$n$$$. It is guaranteed that $$$n$$$ is an odd number. You must perform exactly one of the following operations for each position $$$i \in [1,n]$$$:

  1. Perform no operation at no cost.
  2. Spend a cost of $$$x_i$$$ to either modify $$$p_i$$$ to $$$p_i^2$$$ or modify $$$q_i$$$ to $$$q_i^2$$$.
  3. Spend a cost of $$$y_i$$$ to modify both $$$p_i$$$ to $$$p_i^2$$$ and $$$q_i$$$ to $$$q_i^2$$$.

Please find the minimum cost required to make the median of array $$$p$$$ equal to $$$A$$$ and the median of array $$$q$$$ equal to $$$B$$$. If it's impossible, output $$$-1$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ . The description of the test cases follows.

The first line of each test case contains three single integers $$$n,A,B$$$ $$$(1 \leq n \leq 10^5,1 \leq A,B \leq n^2)$$$.

The second line gives $$$n$$$ positive integers, representing the permutation $$$p$$$.

The third line gives $$$n$$$ positive integers, representing the permutation $$$q$$$.

The fourth line gives $$$n$$$ positive integers, representing the array $$$x$$$ .

The fifth line gives $$$n$$$ positive integers, representing the array $$$y$$$ $$$(1 \leq x_i \leq y_i \leq10^4)$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each test case, output $$$-1$$$ if it is impossible.

Otherwise, output the minimum cost.

All outputs must be printed on separate lines.

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

G. Square Permutation II
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Give two permutations $$$p$$$ and $$$q$$$ of length $$$n$$$. It is guaranteed that $$$n$$$ is an odd number. You must perform exactly one of the following operations for each position $$$i \in [1,n]$$$:

  1. Perform no operation at no cost.
  2. Spend a cost of $$$x$$$ to either modify $$$p_i$$$ to $$$p_i^2$$$ or modify $$$q_i$$$ to $$$q_i^2$$$.
  3. Spend a cost of $$$y$$$ to modify both $$$p_i$$$ to $$$p_i^2$$$ and $$$q_i$$$ to $$$q_i^2$$$.

There are a total of $$$m$$$ groups of queries in this problem. For each query, values of $$$x$$$ , $$$y$$$ , $$$A$$$ and $$$B$$$ are given.Please find the minimum cost required to make the median of array $$$p$$$ equal to $$$A$$$ and the median of array $$$q$$$ equal to $$$B$$$. If it's impossible, output $$$-1$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ $$$(1 \leq t \leq 10^4)$$$ . The description of the test cases follows.

The first line of each test case contains two single integers $$$n,m$$$ $$$(1\leq n,m\leq 10^5)$$$.

The second line gives $$$n$$$ positive integers, representing the permutation $$$p$$$.

The third line gives $$$n$$$ positive integers, representing the permutation $$$q$$$.

The next $$$m$$$ lines each contain four positive integers $$$A$$$, $$$B$$$, $$$x$$$, and $$$y$$$ $$$(1 \leq A,B \leq n^2,1 \leq x \leq y \leq 10^9)$$$.

It is guaranteed that the sum of $$$n$$$ and $$$m$$$ over all test cases does not exceed $$$10^5$$$.

Output

For each set of data, output $$$m$$$ lines. The $$$i$$$-th line contains an integer representing the answer to the $$$i$$$-th query.

Example
Input
1
5 6
1 3 2 5 4
3 2 1 4 5
4 9 1 4
5 9 1 3
5 16 3 3
16 5 3 4
5 5 2 3
9 9 10 11
Output
4
6
-1
-1
8
42

H. Tree Shuffling
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Froggy has an unrooted tree $$$T$$$ with $$$n$$$ vertices, where each vertex has an initial weight. Initially, the weight of vertex $$$i$$$ is $$$i$$$.

Froggy can perform at most 1 operation sequentially as follows:

  • Select several distinct vertices $$$x_1, x_2, \cdots, x_k$$$, such that for $$$i = 1, 2, \cdots, k-1$$$, there exists an edge in tree $$$T$$$ connecting vertex $$$x_i$$$ and vertex $$$x_{i+1}$$$.
  • From the set $$${x_1, x_2, \cdots, x_k}$$$, choose an even number of vertices $$$u_1, u_2, \cdots, u_{2l}$$$ (vertices can be chosen repeatedly). For $$$i = 1, 2, \cdots, l$$$, sequentially swap the weights of vertex $$$u_{2i-1}$$$ and vertex $$$u_{2i}$$$.

Let $$$a_i$$$ denote the weight of vertex $$$i$$$ after all operations. How many distinct sequences $$$a_1, a_2, \cdots, a_n$$$ can Froggy obtain? Output the answer modulo $$$998244353$$$.

Input

The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 10^3)$$$, indicating the number of test cases.

For each test case, the first line contains an integer $$$n$$$ $$$(1 \leq n \leq 3000)$$$, representing the number of vertices in the tree.

The next $$$n-1$$$ lines each contain two positive integers $$$x, y$$$ $$$(1 \leq x, y \leq n, x \neq y)$$$, representing the two endpoints of an edge in tree $$$T$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases in a single test point does not exceed $$$1.5 \times 10^4$$$.

Output

For each test case, output one integer representing the answer modulo $$$998244353$$$.

Example
Input
3
5
1 2
1 3
1 4
1 5
6
1 2
1 3
1 4
2 5
2 6
6
1 2
2 3
2 4
3 5
4 6
Output
23
80
155

I. DAG Query
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

This is an interactive problem.

Given a directed acyclic graph (DAG) with $$$n$$$ vertices and $$$m$$$ edges, each edge has an associated weight.

There may be multiple paths between any pair of vertices $$$s$$$ and $$$t$$$. We define the weight of a path as the product of the weights of all edges along that path. Let $$$f(s,t,c)$$$ denote the sum of the path weights of all distinct paths from $$$s$$$ to $$$t$$$ after multiplying the weight of every edge in the graph by $$$c$$$. Since the result can be extremely large, $$$f(s,t,c)$$$ is taken modulo $$$998244353$$$.

Xiao M will inform you of the structure of the DAG in advance (excluding the edge weights).

You may provide parameters $$$s$$$, $$$t$$$, and $$$c$$$; the interactor will return the value of $$$f(s,t,c)$$$. You are allowed to make at most $$$999$$$ such queries to obtain certain information about the graph. After several query cycles, the interactor will provide a parameter $$$k$$$, and you need to determine the value of $$$f(1,n,k)$$$.

Input

The first line contains two positive integers $$$n$$$ and $$$m$$$ $$$(1 \leq n \leq 1000,1 \leq m \leq 5000)$$$, where $$$n$$$ represents the number of vertices in the graph and $$$m$$$ represents the number of edges.

In the following $$$m$$$ lines, each line contains two positive integers $$$x$$$ and $$$y$$$ $$$(1 \leq x,y \leq 1000)$$$, indicating that there is a directed edge from vertex $$$x$$$ to vertex $$$y$$$ in the graph. It is guaranteed that the graph is a Directed Acyclic Graph (DAG).

Interaction

For each query, you need to output in the format $$$\texttt{? s t c}$$$ $$$(1\leq s,t\leq n,0\leq c \lt 998244353)$$$ where $$$s,t,c$$$ are all integers, and the interactor will return the answer of $$$f(s,t,c)$$$.

When you are confident that the information you have is sufficient to answer the query, output $$$\texttt{!}$$$, and the interactor will return a integer parameter $$$k$$$ $$$(0\leq k \lt 998244353)$$$, which means you are asked for the weight of $$$f(1,n,k)$$$.

You need to output the result of $$$f(1,n,k)$$$.

After printing a query or the answer, do not forget to output the end of the line and flush the output. Otherwise, you will get the verdict Idleness Limit Exceeded. To do this, use:

$$$\texttt{fflush(stdout)}$$$ or $$$\texttt{cout.flush()}$$$ in C++; $$$\texttt{System.out.flush()}$$$ in Java; $$$\texttt{flush(output)}$$$ in Pascal; $$$\texttt{stdout.flush()}$$$ in Python; see the documentation for other languages.

Example
Input
3 3
1 2
2 3
1 3

1

2

12

123

Output
? 1 2 1

? 2 3 1

? 1 3 1

!

31488

J. Reconstruct the tree
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a remembered collection of $$$\textit{diameter endpoint pairs}$$$ that Little Grey wrote down when he owned a tree with $$$N$$$ nodes. Now he forgot the tree itself. Your task is to reconstruct $$$\textbf{any}$$$ tree on $$$N$$$ labeled nodes whose set of unordered pairs of nodes at distance equal to the tree diameter is exactly the given collection — or report that his memory is inconsistent (i.e. no such tree exists).

A $$$\textit{diameter}$$$ of a tree is the longest simple path in the tree; its length is the maximum distance between any two vertices. A pair $$$(u,v)$$$ is a $$$\textit{diameter endpoint pair}$$$ if the distance between $$$u$$$ and $$$v$$$ equals the length of tree diameter. The given collection contains unordered pairs and may list them in any order.

Input

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 2 \cdot 10^5$$$) — the number of test cases.

Each test case begins with a line containing three integers $$$N, M$$$ ($$$2 \le N \le 2\cdot 10^5,\ 1 \le M \le 2\cdot 10^5$$$) — the number of nodes and the number of remembered unordered pairs.

Then follow $$$M$$$ lines, each containing two integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le N,\ u\ne v$$$), representing an unordered pair that Little Grey remembered as being at distance equal to the length of tree diameter.

$$$\textbf{All}\ M\ \textbf{pairs in one test case are distinct.}$$$

It is guaranteed that $$$\sum N \le 2\cdot 10^5,\sum M \le 2\cdot 10^5 $$$ where sums are over all test cases.

Output

For each test case, print:

If there exists a tree on nodes $$$1\ldots N$$$ whose set of unordered node-pairs at distance equal to the tree diameter is $$$\textbf{exactly}$$$ the given set, print a line YES and then $$$N-1$$$ lines describing any such tree as edges $$$(a, b)$$$ (one edge per line, nodes separated by a space; the tree should be connected and acyclic).

If multiple valid trees exist, you may output any of them.

Otherwise, print a single line NO.

Example
Input
3
2 1
1 2
3 2
1 2
2 3
4 3
1 2
2 3
1 3
Output
YES
1 2
NO
YES
4 1
4 2
4 3

K. The Only Heart
time limit per test
3 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Kikyou has carefully cultivated a tree. Now that the tree has grown lush with branches and leaves, Kikyou decides to prune it.

The tree currently has $$$n$$$ vertices. Kikyou plans to remove some vertices and their adjacent edges such that the remaining part is still connected. It is easy to see that the remaining part is still a tree.

As a heavy cat, Kikyou wants the remaining tree to be wholehearted, meaning it has only one heart. Here, the heart of a tree is defined as a vertex such that when it is removed, the maximum size among the remaining connected components is minimized. If multiple vertices satisfy this condition, they are all considered hearts.

Kikyou wants to know how many such remaining non-empty trees there are where the heart is unique. Output the answer modulo $$$998244353$$$. Two remaining trees are considered different if and only if their vertex sets are different.

Input

The first line contains a positive integer $$$T$$$ $$$(1 \leq T \leq 10^3)$$$, indicating the number of test cases.

For each test case, the first line contains an integer $$$n$$$ $$$(1 \leq n \leq 3000)$$$, representing the number of vertices in the tree.

The next $$$n-1$$$ lines each contain two positive integers $$$x, y$$$ $$$(1 \leq x, y \leq n, x \neq y)$$$, representing the two endpoints of an edge in tree $$$T$$$.

It is guaranteed that the sum of $$$n$$$ over all test cases in a single test point does not exceed $$$1.5 \times 10^4$$$.

Output

For each test case, output one integer representing the answer modulo $$$998244353$$$.

Example
Input
3
5
1 2
1 3
3 4
3 5
6
1 2
1 3
1 4
2 5
2 6
6
1 2
2 3
2 4
3 5
4 6
Output
11
18
16
Note

For the first test case, a single remaining vertex must be the unique heart. Two remaining vertices must form two hearts. Other valid subsets with unique heart include: $$$\{1,2,3\}$$$, $$$\{1,3,4\}$$$, $$$\{1,3,5\}$$$, $$$\{3,4,5\}$$$, $$$\{1,3,4,5\}$$$, and $$$\{1,2,3,4,5\}$$$. The total number of valid subsets is $$$11$$$.

L. Xor Mirror
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Long ago, in the land of Bitworld, there was a magic mirror. Whenever you looked into it, the index $$$i$$$ of an array element would be reflected as $$$i \oplus k$$$ for some magic key $$$k$$$. The wizard who owned this mirror loved to play with sequences: sometimes he mirrored parts of the sequence using XOR, and sometimes he asked for weighted sums of intervals.

Now the wizard gives you $$$T$$$ sequences and a list of operations for each sequence. Your task is to process them and report the results of his queries.

You are given an initial sequence $$$A_0, A_1, \dots, A_{N-1}$$$ of length $$$N$$$. The value $$$N$$$ is always a power of two and satisfies $$$N \le 2^{18}$$$.

There are two types of operations:

  • Operation type 1: given integers $$$(l,r,k)$$$, for every $$$i \in [l,r)$$$ set $$$$$$ B_i = A_{i \oplus k}, $$$$$$ then assign $$$A_i = B_i$$$ for all $$$i \in [l,r)$$$.
  • Operation type 2: given integers $$$(l,r)$$$, output $$$$$$ \sum_{i=l}^{r-1} A_i. $$$$$$
Input

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 2\times 10^5$$$) — the number of test cases.

Each test case is given as:

One line with two integers $$$N$$$ ($$$1 \le N \le 2^{18}$$$, $$$N$$$ is a power of two) and $$$Q$$$ ($$$1 \le Q \le 2\times 10^5$$$) — the length of the sequence and the number of operations.

One line with $$$N$$$ integers $$$A_0, A_1, \dots, A_{N-1}$$$ ($$$1 \le A_i \le 1048576$$$) — the initial sequence.

Each of the next $$$Q$$$ lines describes one operation.

All operations are given on a left-closed, right-open interval $$$[l, r)$$$ with $$$0 \le l \lt r \le N$$$. The formats are:

1 l r k —– apply operation type 1 on the interval $$$[l, r)$$$ with parameter $$$k$$$ ($$$0 \le k \lt N$$$).

2 l r —– apply operation type 2 on the interval $$$[l, r)$$$.

It is guaranteed that $$$\sum N \le 2^{18}$$$, $$$\sum Q \le 2\times 10^5$$$ over all test cases.

Output

For each operation of type 2, output the result on a separate line.

Example
Input
1
8 8
7 3 8 1 4 6 4 1
2 2 7
2 5 7
1 3 5 3
1 5 6 2
2 7 8
2 3 7
1 2 8 5
2 5 8
Output
23
10
1
13
22