Good Bye 2025
A. Yes or Yes
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Last Christmas, your friend Fernando gifted you a string $$$s$$$ consisting only of the characters $$$\mathtt{Y}$$$ and $$$\mathtt{N}$$$, representing "Yes" and "No", respectively.

You can repeatedly apply the following operation on $$$s$$$:

  • Choose any two adjacent characters and replace them with their logical OR.

Formally, in each operation, you can choose an index $$$i$$$ ($$$1 \leq i \leq |s|-1$$$), remove the characters $$$s_i$$$ and $$$s_{i+1}$$$, then insert:

  • A single $$$\mathtt{Y}$$$ if at least one of $$$s_i$$$ or $$$s_{i+1}$$$ is $$$\mathtt{Y}$$$;
  • A single $$$\mathtt{N}$$$ if both $$$s_i$$$ and $$$s_{i+1}$$$ are $$$\mathtt{N}$$$.

Note that after each operation, the length of $$$s$$$ decreases by $$$1$$$.

Unfortunately, Fernando does not want you to combine "Yes OR Yes", as he has experienced trauma relating to a certain song.

Determine whether it is possible to reduce $$$s$$$ to a single character by repeatedly applying the operation above, without ever combining two $$$\mathtt{Y}$$$'s.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 500$$$). The description of the test cases follows.

The only line of each test case contains the string $$$s$$$ ($$$2\le |s|\le 100$$$). It is guaranteed that $$$s_i = \mathtt{Y}$$$ or $$$\mathtt{N}$$$.

Output

For each test case, print "YES" if the string can be reduced to a single character by repeatedly applying the described operation, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Example
Input
7
YY
NN
NNY
YYYNY
NNNNN
YYYYYY
YNNNNN
Output
NO
YES
YES
NO
YES
NO
YES
Note

In the first test case, you cannot combine $$$s_1$$$ and $$$s_2$$$ since they are both $$$\mathtt{Y}$$$. Thus, the answer is NO.

In the third test case, the following is a valid sequence of operations: $$$\mathtt{\underline{NN}Y}\to\mathtt{\underline{NY}}\to\mathtt{Y}$$$. Thus, the answer is YES.

In the fourth test case, there are two possibilities for the first operation: $$$\mathtt{YY\underline{YN}Y}\to \mathtt{YYYY}$$$ or $$$\mathtt{YYY\underline{NY}}\to \mathtt{YYYY}$$$. However, in either case, it is not possible to perform any more operations without combining two $$$\mathtt{Y}$$$'s. Thus, the answer is NO.

In the fifth test case, the following is a valid sequence of operations: $$$\mathtt{N\underline{NN}NN}\to\mathtt{\underline{NN}NN}\to\mathtt{N\underline{NN}}\to\mathtt{\underline{NN}}\to\mathtt{N}$$$. Thus, the answer is YES.

B. Impost or Sus
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

A string $$$w$$$ consisting of lowercase Latin letters is called suspicious if and only if all of the following conditions hold:

  • The letter $$$\mathtt{s}$$$ appears at least twice, and
  • For every occurrence of the letter $$$\mathtt{u}$$$, the two nearest occurrences of $$$\mathtt{s}$$$ are the same number of characters away from the $$$\mathtt{u}$$$.

After watching you finish a string task, your friend Aka has gifted you a string $$$r$$$ consisting only of letters $$$\mathtt{s}$$$ and $$$\mathtt{u}$$$. You can perform the following operation on $$$r$$$:

  • Choose an index $$$i$$$ ($$$1\le i\le |r|$$$), and set $$$r_i$$$ to $$$\mathtt{s}$$$.

Determine the minimum number of operations needed to make $$$r$$$ suspicious. It can be shown that, under the given constraints, it is always possible to transform $$$r$$$ into a suspicious string.

Input

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 only line of each test case contains the string $$$r$$$ ($$$3\le |r|\le 2\cdot 10^5$$$). It is guaranteed that $$$r_i = \mathtt{s}$$$ or $$$\mathtt{u}$$$.

It is guaranteed that the sum of $$$|r|$$$ over all test cases does not exceed $$$2\cdot 10 ^ 5$$$.

Output

For each test case, output a single integer — the minimum number of operations needed to make $$$r$$$ suspicious.

Example
Input
9
sus
uuuu
sssss
uusuuu
suuuuuu
usssssss
sssuuusss
susuusuuus
uuuuuuuuuuu
Output
0
3
0
3
3
1
1
2
6
Note

In the first test case, the string $$$\mathtt{sus}$$$ is already suspicious because $$$\mathtt{s}$$$ appears twice in the string and the two nearest $$$\mathtt{s}$$$ to the only $$$\mathtt{u}$$$ are both $$$1$$$ character away: $$$\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}$$$.

In the second test case, it is optimal to perform the operation on indices $$$1$$$, $$$3$$$, and $$$4$$$. After that, the string $$$s$$$ becomes $$$\texttt{suss}$$$. The string $$$\mathtt{suss}$$$ is suspicious because $$$\mathtt{s}$$$ appears $$$3$$$ times in the string and the two nearest $$$\mathtt{s}$$$ to the only $$$\mathtt{u}$$$ are both $$$1$$$ character away: $$$\color{red}{\mathtt{s}}\underline{\mathtt{u}}\color{red}{\mathtt{s}}\mathtt{s}$$$.

In the third test case, the condition on $$$\mathtt{u}$$$ is vacuously true because there is no $$$\mathtt{u}$$$ in the string $$$\mathtt{sssss}$$$. Thus, the given string is already suspicious.

In the sixth test case, the initial string $$$\mathtt{usssssss}$$$ is not suspicious because the two nearest $$$\mathtt{s}$$$ to the only $$$\mathtt{u}$$$ are one and two characters away, respectively: $$$\underline{\mathtt{u}}\color{red}{\mathtt{ss}}\mathtt{sssss}$$$.

C. First or Second
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

There are $$$n$$$ children standing in a line, where the niceness of the $$$i$$$-th child is $$$a_i$$$. Santa is deciding which children belong on the nice list and which belong on the naughty list.

An integer $$$X$$$ is initially set to $$$0$$$. Santa will perform the following operation exactly $$$n-1$$$ times:

  • Choose the first or second child in line and remove them from the line.
  • Let $$$w$$$ be the niceness of the chosen child.
    • If the first child was chosen, add them to the nice list and add $$$w$$$ to $$$X$$$.
    • If the second child was chosen, add them to the naughty list and subtract $$$w$$$ from $$$X$$$.

Note that after all operations, exactly one child remains unassigned to a list.

Determine the maximum possible value of $$$X$$$ that Santa can obtain after all $$$n-1$$$ operations.

Input

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 a single integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of children.

The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$-10^9\le a_i\le 10^9$$$) — the niceness of each child.

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

Output

For each test case, print a single integer — the maximum possible value of $$$X$$$ that Santa can obtain after all $$$n-1$$$ operations.

Example
Input
7
2
2 -3
4
1 4 3 4
4
-4 2 3 -6
5
-2 -3 4 10 -9
5
-12345678 -1000000000 -999999999 1000000000 -999999999
2
-7 1
5
7 -6 -1 -8 -8
Output
3
8
4
15
2987654321
-1
29
Note

In the first test case, Santa will perform exactly one operation. If he chooses the first child, he will add $$$a_1=2$$$ to $$$X$$$ to get $$$X=2$$$; if he chooses the second child, he will subtract $$$a_2=-3$$$ from $$$X$$$ to get $$$X=3$$$. Thus, the answer is $$$3$$$.

In the second test case, it is optimal to select the first child in all three operations. The value of $$$X$$$ will be $$$1+4+3=8$$$.

In the third test case, below is an optimal sequence of operations:

#TypeNiceness of remaining children$$$X$$$ after operation
0—$$$[-4, 2, 3, -6]$$$$$$0$$$
1First$$$[2, 3, -6]$$$$$$-4$$$
2First$$$[3, -6]$$$$$$-2$$$
3Second$$$[3]$$$$$$4$$$

In the fourth test case, below is an optimal sequence of operations:

#TypeNiceness of remaining children$$$X$$$ after operation
0—$$$[-2, -3, 4, 10, -9]$$$$$$0$$$
1Second$$$[-2, 4, 10, -9]$$$$$$3$$$
2First$$$[4, 10, -9]$$$$$$1$$$
3First$$$[10, -9]$$$$$$5$$$
4First$$$[-9]$$$$$$15$$$

D. Xmas or Hysteria
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Mass Hysteria (Hearthstone)
$$$\color{white}{\text{You are sus}}$$$

Franklin is plotting a Christmas attack where he casts the spell Mass Hysteria on a village of elves.

There are $$$n$$$ elves numbered $$$1$$$ to $$$n$$$, where elf $$$i$$$ has a health value of $$$h_i$$$ and an attack value of $$$a_i$$$. Initially, $$$h_i=a_i$$$ for all $$$i$$$, and all $$$a_i$$$ are distinct. Elf $$$i$$$ is alive if and only if its health is positive (i.e., $$$h_i \gt 0$$$).

When Franklin casts Mass Hysteria, the following process is repeated:

  • Choose a pair of distinct living elves $$$x$$$ and $$$y$$$ ($$$h_x,h_y \gt 0$$$) such that elf $$$x$$$ has not attacked before. If no such pair exists, terminate the process.
  • Then, elf $$$x$$$ attacks elf $$$y$$$, decreasing $$$h_y$$$ by $$$a_x$$$. Additionally, due to recoil, $$$h_x$$$ is decreased by $$$a_y$$$. Note that $$$a_x$$$ and $$$a_y$$$ remain unchanged.

The process will repeat until it is impossible to choose a valid pair of elves. It can be shown that Mass Hysteria terminates after at most $$$n$$$ iterations.

Given an integer $$$m$$$, construct a valid sequence of attacks such that exactly $$$m$$$ elves are alive when the process ends; or determine that no such sequence exists.

Input

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 two integers $$$n$$$ and $$$m$$$ ($$$2\le n\le 2\cdot 10^5, 0\le m\le n$$$) — the number of elves in the village and the number of elves to be left alive.

The second line contains $$$n$$$ integers $$$a_1,a_2,\ldots,a_n$$$ ($$$1\le a_i\le 10^9$$$) — the initial attack and health values of the elves.

It is guaranteed that all $$$a_i$$$ are distinct.

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

Output

For each test case, if it is impossible for exactly $$$m$$$ elves to remain alive, print $$$-1$$$.

Otherwise, output a valid sequence of attacks as follows:

  • On the first line, output an integer $$$k$$$ ($$$0\le k\le n$$$) — the number of iterations in Mass Hysteria.
  • Then $$$k$$$ lines follow, the $$$i$$$-th line containing two integers $$$x_i$$$ and $$$y_i$$$ ($$$1\leq x_i,y_i\leq n$$$, $$$x_i\neq y_i$$$), indicating that elf $$$x_i$$$ attacks elf $$$y_i$$$ in the $$$i$$$-th iteration.

The sequence must satisfy all of the following conditions:

  • Immediately before the $$$i$$$-th iteration, both elves $$$x_i$$$ and $$$y_i$$$ are alive and elf $$$x_i$$$ has not attacked in any previous iteration.
  • After the $$$k$$$-th iteration, exactly $$$m$$$ elves are alive and there does not exist a pair of distinct living elves $$$x$$$ and $$$y$$$ such that elf $$$x$$$ has not attacked before.

If there are multiple answers, you may output any of them. Any valid sequence satisfying the above conditions will be accepted.

Example
Input
7
4 2
1 4 2 3
2 2
6 7
3 0
1 2 3
3 1
1 2 3
3 2
1 2 3
4 1
2 3 4 5
6 0
998244353 1000000000 314159265 676767677 999999999 987654321
Output
2
3 1
2 4
-1
2
3 2
1 3
2
1 2
3 2
-1
2
1 4
4 2
4
3 1
2 5
6 1
4 2
Note

In the first test case, one possible sequence of attacks is shown below:

#$$$x$$$$$$y$$$Health values after attackElves that have attacked
0——$$$[1, 4, 2, 3]$$$$$$[]$$$
1$$$3$$$$$$1$$$$$$[-1, 4, 1, 3]$$$$$$[3]$$$
2$$$2$$$$$$4$$$$$$[-1, 1, 1, -1]$$$$$$[2, 3]$$$

After $$$2$$$ iterations, only elves $$$2$$$ and $$$3$$$ are alive. Since both of them have already attacked, no further valid attack is possible, and Mass Hysteria terminates.

In the second test case, the only possible choices for $$$(x,y)$$$ in the first iteration are $$$(1,2)$$$ or $$$(2,1)$$$. In either case, elf $$$1$$$ ends up with $$$-1$$$ health, so it is impossible for both elves to remain alive at the end. Note that Mass Hysteria will last at least one iteration as there exists a valid $$$(x,y)$$$ for the first iteration.

In the sixth test case, only elf $$$3$$$ is alive after all attacks. Even though elf $$$3$$$ has not attacked before, Mass Hysteria terminates since there is no other elf it can attack.

E. Flatten or Concatenate
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

This is an interactive problem.

While procrastinating at work, Dilhan the elf stumbled upon two arrays $$$a$$$ and $$$b$$$. Initially, both of them consist of a single integer $$$2^k$$$ (i.e., $$$a=b=[2^k]$$$), where $$$k$$$ is a non-negative integer.

Dilhan then applied the following two types of operations an arbitrary number of times (possibly zero), in any order:

  1. Flatten — Choose either $$$a$$$ or $$$b$$$, and select any element $$$x$$$ that is maximal within that array ($$$x$$$ does not need to be maximal in the other array). Then, replace $$$x$$$ with two copies of $$$\frac x2$$$ in the same position. This operation can only be applied if $$$x$$$ is even.
  2. Concatenate — Set both $$$a$$$ and $$$b$$$ to be $$$a+b$$$, where $$$+$$$ denotes array concatenation.

After performing these operations, Dilhan discards $$$b$$$, hides $$$a$$$ from you, and challenges you to a game.

Let $$$n$$$ be the length of the hidden array $$$a$$$. You may make the following query:

  • Choose an interval $$$[l, r]$$$ ($$$1\le l\le r\le n$$$), and Dilhan will tell you the sum $$$a_l+a_{l+1}+\cdots+a_r$$$.

Determine the value of the maximum element of $$$a$$$ by making at most $$$300$$$ queries.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). The description of the test cases follows.

The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of $$$a$$$.

It is guaranteed that $$$1\le a_i\le 2^{30}$$$, and the array $$$a$$$ can be generated by the process described in the statements.

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

Interaction

For each test case, you are first given an integer $$$n$$$ — the length of the hidden array $$$a$$$. You may then make up to $$$300$$$ queries.

To make a query, print a line in the following format:

  • $$$\texttt{?}\;l\;r$$$ ($$$1\le l\le r\le n$$$) — the indices chosen for the query.

After you print a query, the interactor will respond with a single integer — the sum $$$a_l+a_{l+1}+\ldots+a_r$$$.

To report that you have determined the value of the maximum element of $$$a$$$, print your answer in the following format:

  • $$$\texttt{!}\; m$$$ ($$$1\le m\le 2^{30}$$$) — the value of the maximum element.

Printing the answer does not count as one of the $$$300$$$ queries.

After printing the answer, proceed to the next test case. If the current test case is the last one, terminate the program.

After printing each query do not forget to output the end of line and flush$$$^{\text{∗}}$$$ the output. Otherwise, you will get Idleness limit exceeded verdict.

If, at any interaction step, you read $$$-1$$$ instead of valid data, your solution must exit immediately. This means that your solution will receive Wrong answer because of an invalid query or any other mistake. Failing to exit can result in an arbitrary verdict because your solution will continue to read from a closed stream.

The interactor in this problem is not adaptive. In other words, the array $$$a$$$ is fixed before any queries and will not change during the interaction.

Hacks are disabled in this problem.

$$$^{\text{∗}}$$$To flush, use:

  • fflush(stdout) or cout.flush() in C++;
  • sys.stdout.flush() in Python;
  • see the documentation for other languages.
Example
Input
4
11

9

4

12

1

1

8

4

4

4

4

8

Output


? 3 8

? 1 4

? 5 11

! 2

? 1 1

! 1

? 1 1

? 2 2

? 3 3

? 4 4

! 4

! 1073741824
Note

In the first test case, Dilhan's hidden array $$$a$$$ is $$$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$$$. It can be generated by the following process:

#Type$$$a$$$ after operation$$$b$$$ after operation
0$$$[4]$$$$$$[4]$$$
1Flatten $$$a$$$$$$[\underline 4] \to {[2, 2]}$$$$$$[4]$$$
2Flatten $$$b$$$$$$[2, 2]$$$$$$[\underline 4] \to {[2, 2]}$$$
3Flatten $$$a$$$$$$[2, \underline 2] \to {[2, 1, 1]}$$$$$$[2, 2]$$$
4Concatenate$$$[2, 1, 1, 2, 2]$$$$$$[2, 1, 1, 2, 2]$$$
5Flatten $$$a$$$$$$[\underline 2, 1, 1, 2, 2]\to {[1, 1, 1, 1, 2, 2]}$$$$$$[2, 1, 1, 2, 2]$$$
6Concatenate$$$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$$$$$$[1, 1, 1, 1, 2, 2, 2, 1, 1, 2, 2]$$$
  • For the query $$$\mathtt{?\;3\;8}$$$, the jury responded with $$$1+1+2+2+2+1=9$$$;
  • For the query $$$\mathtt{?\;1\;4}$$$, the jury responded with $$$1+1+1+1=4$$$;
  • For the query $$$\mathtt{?\;5\;11}$$$, the jury responded with $$$2+2+2+1+1+2+2=12$$$.

And the value of the maximum element of $$$a$$$ is $$$2$$$.

In the second test case, the array $$$a$$$ has only one element. By the query, the value of the only element is $$$1$$$, and it must also be the maximum value.

In the third test case, Dilhan's hidden array $$$a$$$ is $$$[4, 4, 4, 4, 4, 4, 4, 4]$$$. It can be generated by the following process:

#Type$$$a$$$ after operation$$$b$$$ after operation
0$$$[4]$$$$$$[4]$$$
1Concatenate$$$[4, 4]$$$$$$[4, 4]$$$
2Concatenate$$$[4, 4, 4, 4]$$$$$$[4, 4, 4, 4]$$$
3Concatenate$$$[4, 4, 4, 4, 4, 4, 4, 4]$$$$$$[4, 4, 4, 4, 4, 4, 4, 4]$$$

And the value of the maximum element of $$$a$$$ is $$$4$$$.

In the fourth test case, Dilhan's hidden array $$$a$$$ is $$$[2^{29}, 2^{29}, 2^{30}, 2^{29}, 2^{28}, 2^{28}, 2^{29}, 2^{29}]$$$.

F. Conquer or of Forest
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Define the unique ornamental coloring of a rooted tree$$$^{\text{∗}}$$$ as the following vertex coloring:

  • A vertex $$$v$$$ is colored white if the number of vertices in the subtree$$$^{\text{†}}$$$ rooted at $$$v$$$ is even;
  • Otherwise, $$$v$$$ is colored black.

On his quest to conquer a forest of Christmas trees, Yuuki encountered an ornamentally colored tree $$$T$$$ with $$$n$$$ vertices labeled from $$$1$$$ to $$$n$$$, rooted at vertex $$$1$$$.

Yuuki considers the tree conquered if and only if at least one of the following conditions holds:

  • There are no white vertices in the tree, or
  • There exists some vertex $$$v$$$ such that all white vertices lie on the simple path from the root $$$1$$$ to $$$v$$$.

To conquer the tree, Yuuki can apply the following operation on $$$T$$$ an arbitrary number of times (possibly zero):

  • First, choose a vertex $$$w$$$ that is colored white and is not the root of $$$T$$$. Let $$$p_w$$$ be the parent of $$$w$$$.
  • Then, remove the edge connecting $$$p_w$$$ and $$$w$$$, and add an edge between any two vertices such that $$$T$$$ remains a tree.
  • Finally, recolor the vertices of $$$T$$$ such that it is ornamentally colored. Note that $$$T$$$ is always rooted at vertex $$$1$$$.
A possible application of the operation in the first test case. The resulting tree is conquered since all white vertices lie on the path between vertices $$$1$$$ and $$$3$$$.

Compute the number of distinct$$$^{\text{‡}}$$$ conquered trees that Yuuki can construct by applying the above operation an arbitrary number of times on $$$T$$$. Since the answer may be large, output it modulo $$$998\,244\,353$$$.

Note that Yuuki cannot stop midway through an operation (in particular, he must recolor the tree before checking if it is conquered). Additionally, Yuuki is allowed to apply the operation even if the tree is already conquered.

$$$^{\text{∗}}$$$A tree is a connected graph without cycles.

$$$^{\text{†}}$$$A subtree of vertex $$$v$$$ is the subgraph of $$$v$$$, all its descendants, and all the edges between them.

$$$^{\text{‡}}$$$Two trees are considered distinct if and only if there exists a pair of vertices such that there is an edge between them in one of the trees, and not in the other.

Input

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 a single integer $$$n$$$ ($$$2\le n\le 2\cdot 10^5$$$) — the number of vertices in $$$T$$$.

Then $$$n-1$$$ lines follow, the $$$i$$$-th line containing two integers $$$u_i$$$ and $$$v_i$$$ ($$$1\le u_i \lt v_i\le n$$$) — the two vertices that the $$$i$$$-th edge connects.

It is guaranteed that the given edges form a tree.

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

Output

For each test case, output a single integer — the number of distinct conquered trees that can be constructed from $$$T$$$, modulo $$$998\,244\,353$$$.

Example
Input
5
4
1 2
1 3
3 4
5
1 2
1 3
1 4
1 5
5
1 2
2 3
1 4
4 5
6
1 2
2 3
2 4
2 6
5 6
11
2 10
6 8
1 6
3 7
5 11
5 8
5 9
4 7
6 7
2 6
Output
4
1
16
8
2048
Note

In the first test case, below are the four conquered trees that can be constructed and a sequence of operations that constructs each one.

Explanation
Illustration
  • The operation is applied zero times.
  • The given tree is already conquered since all white vertices lie on the simple path between vertices $$$1$$$ and $$$4$$$.
  • The first and only operation selects $$$w$$$ to be vertex $$$3$$$ ($$$p_w$$$ is vertex $$$1$$$) and draws an edge between vertices $$$2$$$ and $$$4$$$.
  • The resulting tree is conquered since all white vertices lie on the simple path between vertices $$$1$$$ and $$$3$$$.
  • The first and only operation selects $$$w$$$ to be vertex $$$3$$$ ($$$p_w$$$ is vertex $$$1$$$) and draws an edge between vertices $$$2$$$ and $$$3$$$.
  • The resulting tree is conquered since all white vertices lie on the simple path between vertices $$$1$$$ and $$$3$$$.
  • The first operation selects $$$w$$$ to be vertex $$$3$$$ ($$$p_w$$$ is vertex $$$1$$$) and draws an edge between vertices $$$2$$$ and $$$4$$$.
  • The second operation selects $$$w$$$ to be vertex $$$4$$$ ($$$p_w$$$ is vertex $$$2$$$) and draws an edge between vertices $$$1$$$ and $$$4$$$.
  • The resulting tree is conquered since all white vertices lie on the simple path between vertices $$$1$$$ and $$$4$$$.

In the second test case, Yuuki cannot apply the operation on $$$T$$$ since there are no white vertices. Additionally, $$$T$$$ is already conquered since there are no white vertices. Thus, the answer is $$$1$$$.

G. deCH OR Dations
time limit per test
3 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Due to supply chain issues in the North Pole (allegedly caused by a lazy elf), Santa is planning to give out hand-drawn circles as presents this Christmas. Please help him decorate them!

There are $$$2n$$$ equally spaced points around the circle, labeled $$$1,2,\ldots,2n$$$ in clockwise order. Santa has chosen $$$n$$$ chords with distinct endpoints, where chord $$$i$$$ connects the points $$$a_i$$$ and $$$b_i$$$. He draws these chords onto the circle one by one, in order.

After Santa has drawn the first $$$\ell$$$ chords, consider any non-empty subset $$$S$$$ of the $$$\ell$$$ chords and let $$$1\leq c_1 \lt c_2 \lt \cdots \lt c_{|S|}\leq \ell$$$ be their indices. $$$S$$$ is defined to be a chain if and only if chord $$$c_k$$$ intersects chord $$$c_{k+1}$$$ for all $$$1\leq k \lt |S|$$$. Note that $$$S$$$ is always a chain if $$$|S|=1$$$.

Santa does not want any chord to be the odd one out. Therefore, he considers the chords to be tight-knit if and only if every chord appears in an even number of chains, taken over all chains that are subsets of the first $$$\ell$$$ chords.

For each $$$\ell$$$ from $$$1$$$ to $$$n$$$, help Santa determine whether his chords are tight-knit.

Input

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 a single integer $$$n$$$ ($$$2\le n\le 5\cdot 10^5$$$) — the number of chords.

Then $$$n$$$ lines follow, the $$$i$$$-th line containing two integers $$$a_i$$$ and $$$b_i$$$ ($$$1\le a_i \lt b_i\le 2n$$$) — the endpoints of the $$$i$$$-th chord.

It is guaranteed that all endpoints are distinct.

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

Output

For each test case, output a string of length $$$n$$$ — the $$$\ell$$$-th character should be $$$\texttt{1}$$$ if the first $$$\ell$$$ chords are tight-knit and $$$\texttt{0}$$$ otherwise.

Example
Input
3
3
1 6
2 3
4 5
4
1 7
3 8
4 6
2 5
5
1 6
4 9
2 7
5 10
3 8
Output
000
0100
01111
Note

In the first test case, no pairs of chords intersect, and thus every chord appears in exactly one chain consisting of itself. Therefore, the chords are not tight-knit for all $$$\ell$$$.

In the second test case, below is an illustration and explanation after the first $$$\ell=1,2,3,4$$$ chords are drawn. Sets of chords are denoted as a set of the indices of the corresponding chords.

Explanation
Illustration
Chains
  • $$$\{1\}$$$.
Appearances
  • Chord $$$1$$$ appears in $$$1$$$ chain.
Notes
  • The chords are not tight-knit since chord $$$1$$$ is in an odd number of chains.
  • Recall that a set containing a single chord is always a chain.
Chains
  • $$$\{1\}$$$, $$$\{1,2\}$$$, and $$$\{2\}$$$.
Appearances
  • Chord $$$1$$$ appears in $$$2$$$ chains;
  • Chord $$$2$$$ appears in $$$2$$$ chains.
Notes
  • The chords are tight-knit since every chord appears in an even number of chains.
Chains
  • $$$\{1\}$$$, $$$\{1,2\}$$$, $$$\{2\}$$$, and $$$\{3\}$$$.
Appearances
  • Chord $$$1$$$ appears in $$$2$$$ chains;
  • Chord $$$2$$$ appears in $$$2$$$ chains;
  • Chord $$$3$$$ appears in $$$1$$$ chain.
Notes
  • The chords are not tight-knit since chord $$$3$$$ is in an odd number of chains.
Chains
  • $$$\{1\}$$$, $$$\{1,2\}$$$, $$$\{1,2,4\}$$$, $$$\{2\}$$$, $$$\{2,4\}$$$, $$$\{3\}$$$, $$$\{3,4\}$$$, and $$$\{4\}$$$.
Appearances
  • Chord $$$1$$$ appears in $$$3$$$ chains;
  • Chord $$$2$$$ appears in $$$4$$$ chains;
  • Chord $$$3$$$ appears in $$$2$$$ chains;
  • Chord $$$4$$$ appears in $$$4$$$ chains.
Notes
  • The chords are not tight-knit since chord $$$1$$$ is in an odd number of chains.
  • Note that $$$\{2,3,4\}$$$ is not a chain since chord $$$2$$$ does not intersect chord $$$3$$$.

Thus, we output $$$\mathtt{0100}$$$.

H. Create or Duplicate
time limit per test
6 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Santa realized that hand-drawing circles takes too long, so he has turned to magic to meet his production quotas.

There are three types of presents with distinct values $$$a$$$, $$$b$$$, and $$$c$$$. Initially, Santa has exactly one present of each type.

You are given two integers $$$m$$$ and $$$k$$$, representing Santa's favorite number and the cost of duplication, respectively. Santa can cast the following two types of spells any number of times (possibly zero):

  1. Create — Choose a type of present and create one additional present of that type. This spell costs $$$x$$$ mana, where $$$x\in \{a,b,c\}$$$ is the value of the chosen type.
  2. Duplicate — Choose a type of present and duplicate all presents of that type. This spell costs $$$k$$$ mana.

Santa wants to perform a sequence of spells such that the sum of the values of all presents is a multiple of $$$m$$$ after the spells.

Determine the minimum amount of mana Santa needs to achieve this. It can be shown that, under the given constraints, such a sequence of spells always exists.

Input

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 only line of each test case contains five integers $$$a$$$, $$$b$$$, $$$c$$$, $$$m$$$, and $$$k$$$ ($$$1\leq a \lt b \lt c \lt m\leq 5\cdot 10^5$$$, $$$1\leq k\leq 5\cdot 10^5$$$).

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

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

Output

For each test case, output a single integer — the minimum amount of mana Santa needs to make the sum of the values of all presents a multiple of $$$m$$$.

Example
Input
7
1 2 3 21 4
3 4 5 12 34
3 12 14 18 1
6 7 8 10 3
100 103 282 488 221
307 2000 5096 12018 5764
194093 292793 395323 475619 490151
Output
10
0
17
9
1227
35116
7050242
Note

Let $$$\ell$$$ be the list of values of presents and $$$\operatorname{sum}(\ell)$$$ be the sum of all elements in $$$\ell$$$.

In the first test case, below is an optimal sequence of operations:

#OperationValue$$$\ell$$$ after operation$$$\operatorname{sum}(\ell)$$$Cost
0——$$$[1, 2, 3]$$$$$$6$$$—
1Create$$$3$$$$$$[1, 2, 3, 3]$$$$$$9$$$$$$3$$$
2Create$$$3$$$$$$[1, 2, 3, 3, 3]$$$$$$12$$$$$$3$$$
3Duplicate$$$3$$$$$$[1, 2, 3, 3, 3, 3, 3, 3]$$$$$$21$$$$$$4$$$
$$$21=7\cdot 3$$$Total: $$$10$$$

In the second test case, it is optimal to not perform any operations because $$$3+4+5=12$$$ is already a multiple of $$$12$$$.

In the third test case, below is an optimal sequence of operations:

#OperationValue$$$\ell$$$ after operation$$$\operatorname{sum}(\ell)$$$Cost
0——$$$[3, 12, 14]$$$$$$29$$$—
1Duplicate$$$12$$$$$$[3, 12, 12, 14]$$$$$$41$$$$$$1$$$
2Duplicate$$$14$$$$$$[3, 12, 12, 14, 14]$$$$$$55$$$$$$1$$$
3Create$$$14$$$$$$[3, 12, 12, 14, 14, 14]$$$$$$69$$$$$$14$$$
4Duplicate$$$3$$$$$$[3, 3, 12, 12, 14, 14, 14]$$$$$$72$$$$$$1$$$
$$$72=18\cdot 4$$$Total: $$$17$$$

I. Numbers or Fireworks
time limit per test
12 seconds
memory limit per test
1024 megabytes
input
standard input
output
standard output

Now that all the presents have been delivered, the North Pole is finally at peace — and it's time to celebrate with a spectacular New Year's fireworks show!

The North Pole is modeled as the Cartesian plane, with $$$n$$$ cities located at distinct lattice points. You are also given an integer $$$k$$$.

For a proper subset$$$^{\text{∗}}$$$ $$$T$$$ of the cities ($$$T$$$ may be empty), we define its explosiveness as follows:

  1. A firework is launched from every city in $$$T$$$.
  2. For each city $$$c$$$ not in $$$T$$$, let $$$f$$$ be the number of fireworks launched from cities that are exactly $$$\sqrt{k}$$$ Euclidean distance$$$^{\text{†}}$$$ away from $$$c$$$. Assign the number $$$(f+1)$$$ to this city $$$c$$$.
  3. The explosiveness of $$$T$$$ is the product of all numbers assigned in Step 2.

Compute the sum of the explosiveness of $$$T$$$ over all $$$2^n-1$$$ proper subsets $$$T$$$ of the cities. Since the answer may be large, output it modulo $$$998\,244\,353$$$.

$$$^{\text{∗}}$$$A proper subset is any subset which is not equal to the whole set.

$$$^{\text{†}}$$$The Euclidean distance between two points $$$(x, y)$$$ and $$$(p, q)$$$ is defined as $$$\sqrt{(x - p)^2 + (y - q)^2}$$$.

Input

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). The description of the test cases follows.

The first line of each test case contains two integers $$$n$$$ and $$$k$$$ ($$$2\le n\le 31$$$, $$$1\leq k \leq2\cdot 10^4$$$).

Then $$$n$$$ lines follow, the $$$i$$$-th line containing two integers $$$x_i$$$ and $$$y_i$$$ ($$$1\leq x_i, y_i\leq 100$$$) — the $$$x$$$ and $$$y$$$ coordinates of the $$$i$$$-th city, respectively. It is guaranteed that the coordinates of the cities are pairwise distinct.

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

Output

For each test case, print a single integer — the sum, modulo $$$998\,244\,353$$$, of the explosiveness over all proper subsets $$$T$$$ of the cities.

Example
Input
4
3 1
1 2
2 1
2 2
2 20000
1 1
100 100
9 5
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
13 25
50 50
55 50
54 53
53 54
50 55
47 54
46 53
45 50
46 47
47 46
50 45
53 46
54 47
Output
16
3
8255
560112
Note

In the first test case, below are the $$$2^3-1=7$$$ possible placements of fireworks. The numbers assigned to cities not in $$$T$$$ are circled.

The total explosiveness is $$$(1\cdot 1\cdot 1)+(1\cdot 2)+(2\cdot 1)+(2\cdot 2)+(3)+(2)+(2)=16$$$.

In the second test case, there are $$$2^2-1=3$$$ possible placements of fireworks. For every placement, since $$$(1,1)$$$ and $$$(100,100)$$$ have a Euclidean distance of $$$\sqrt{(100-1)^2+(100-1)^2}=\sqrt{19\,602}\neq\sqrt{20\,000}$$$, none of the cities will have fireworks that are exactly $$$\sqrt{k}$$$ away. Thus, the number $$$1$$$ is assigned to every city without fireworks. Therefore, the explosiveness is $$$1$$$ for every $$$T$$$, and the answer is $$$1+1+1=3$$$.