AmShZ has traveled to Italy from Iran for the Thom Yorke concert. There are $$$n$$$ cities in Italy indexed from $$$1$$$ to $$$n$$$ and $$$m$$$ directed roads indexed from $$$1$$$ to $$$m$$$. Initially, Keshi is located in the city $$$1$$$ and wants to go to AmShZ's house in the city $$$n$$$. Since Keshi doesn't know the map of Italy, AmShZ helps him to see each other as soon as possible.In the beginning of each day, AmShZ can send one of the following two messages to Keshi: AmShZ sends the index of one road to Keshi as a blocked road. Then Keshi will understand that he should never use that road and he will remain in his current city for the day. AmShZ tells Keshi to move. Then, Keshi will randomly choose one of the cities reachable from his current city and move there. (city $$$B$$$ is reachable from city $$$A$$$ if there's an out-going road from city $$$A$$$ to city $$$B$$$ which hasn't become blocked yet). If there are no such cities, Keshi will remain in his current city.Note that AmShZ always knows Keshi's current location. AmShZ and Keshi want to find the smallest possible integer $$$d$$$ for which they can make sure that they will see each other after at most $$$d$$$ days. Help them find $$$d$$$.

The first line of the input contains two integers $$$n$$$ and $$$m$$$ $$$(2 \le n \le 2 \cdot 10^5, 1 \le m \le 2 \cdot 10^5)$$$  — the number of cities and roads correspondingly. The $$$i$$$-th line of the following $$$m$$$ lines contains two integers $$$v_i$$$ and $$$u_i$$$ $$$(1 \le v_i , u_i \le n,v_i \neq u_i)$$$, denoting a directed road going from city $$$v_i$$$ to city $$$u_i$$$. It is guaranteed that there is at least one route from city $$$1$$$ to city $$$n$$$. Note that there may be more than one road between a pair of cities in each direction.

Output the smallest possible integer $$$d$$$ to make sure that AmShZ and Keshi will see each other after at most $$$d$$$ days.

NoteIn the first sample, it's enough for AmShZ to send the second type of message.In the second sample, on the first day, AmShZ blocks the first road. So the only reachable city from city $$$1$$$ will be city $$$4$$$. Hence on the second day, AmShZ can tell Keshi to move and Keshi will arrive at AmShZ's house.It's also possible for AmShZ to tell Keshi to move for two days.


You are given an array $$$a$$$ that contains $$$n$$$ integers. You can choose any proper subsegment $$$a_l, a_{l + 1}, \ldots, a_r$$$ of this array, meaning you can choose any two integers $$$1 \le l \le r \le n$$$, where $$$r - l + 1 < n$$$. We define the beauty of a given subsegment as the value of the following expression:$$$$$$\max(a_{1}, a_{2}, \ldots, a_{l-1}, a_{r+1}, a_{r+2}, \ldots, a_{n}) - \min(a_{1}, a_{2}, \ldots, a_{l-1}, a_{r+1}, a_{r+2}, \ldots, a_{n}) + \max(a_{l}, \ldots, a_{r}) - \min(a_{l}, \ldots, a_{r}).$$$$$$Please find the maximum beauty among all proper subsegments.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. Then follow the descriptions of each test case. The first line of each test case contains a single integer $$$n$$$ $$$(4 \leq n \leq 10^5)$$$ — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_{i} \leq 10^9$$$) — the elements of the given array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each testcase print a single integer — the maximum beauty of a proper subsegment.

NoteIn the first test case, the optimal segment is $$$l = 7$$$, $$$r = 8$$$. The beauty of this segment equals to $$$(6 - 1) + (5 - 1) = 9$$$.In the second test case, the optimal segment is $$$l = 2$$$, $$$r = 4$$$. The beauty of this segment equals $$$(100 - 2) + (200 - 1) = 297$$$.


You are given a matrix consisting of $$$n$$$ rows and $$$m$$$ columns. Each cell of this matrix contains $$$0$$$ or $$$1$$$.Let's call a square of size $$$2 \times 2$$$ without one corner cell an L-shape figure. In one operation you can take one L-shape figure, with at least one cell containing $$$1$$$ and replace all numbers in it with zeroes.Find the maximum number of operations that you can do with the given matrix.

The first line contains one integer $$$t$$$ ($$$1 \leq t \leq 500$$$) — the number of test cases. Then follow the descriptions of each test case. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2 \leq n, m \leq 500$$$) — the size of the matrix. Each of the following $$$n$$$ lines contains a binary string of length $$$m$$$ — the description of the matrix. It is guaranteed that the sum of $$$n$$$ and the sum of $$$m$$$ over all test cases does not exceed $$$1000$$$.

For each test case output the maximum number of operations you can do with the given matrix.

NoteIn the first testcase one of the optimal sequences of operations is the following (bold font shows l-shape figure on which operation was performed):   Matrix before any operation was performed:  101111011110  Matrix after $$$1$$$ operation was performed:  100101011110  Matrix after $$$2$$$ operations were performed:  100100011110  Matrix after $$$3$$$ operations were performed:  100100010110  Matrix after $$$4$$$ operations were performed:  100000010110  Matrix after $$$5$$$ operations were performed:  100000010100  Matrix after $$$6$$$ operations were performed:  100000000100  Matrix after $$$7$$$ operations were performed:  000000000100  Matrix after $$$8$$$ operations were performed:  000000000000 In the third testcase from the sample we can not perform any operation because the matrix doesn't contain any ones.In the fourth testcase it does not matter which L-shape figure we pick in our first operation. We will always be left with single one. So we will perform $$$2$$$ operations.


It is the hard version of the problem. The only difference is that in this version $$$a_i \le 10^9$$$.You are given an array of $$$n$$$ integers $$$a_0, a_1, a_2, \ldots a_{n - 1}$$$. Bryap wants to find the longest beautiful subsequence in the array.An array $$$b = [b_0, b_1, \ldots, b_{m-1}]$$$, where $$$0 \le b_0 < b_1 < \ldots < b_{m - 1} < n$$$, is a subsequence of length $$$m$$$ of the array $$$a$$$.Subsequence $$$b = [b_0, b_1, \ldots, b_{m-1}]$$$ of length $$$m$$$ is called beautiful, if the following condition holds:   For any $$$p$$$ ($$$0 \le p < m - 1$$$) holds: $$$a_{b_p} \oplus b_{p+1} < a_{b_{p+1}} \oplus b_p$$$. Here $$$a \oplus b$$$ denotes the bitwise XOR of $$$a$$$ and $$$b$$$. For example, $$$2 \oplus 4 = 6$$$ and $$$3 \oplus 1=2$$$.Bryap is a simple person so he only wants to know the length of the longest such subsequence. Help Bryap and find the answer to his question.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_0,a_1,...,a_{n-1}$$$ ($$$0 \leq a_i \leq 10^9$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case print a single integer — the length of the longest beautiful subsequence.

NoteIn the first test case, we can pick the whole array as a beautiful subsequence because $$$1 \oplus 1 < 2 \oplus 0$$$.In the second test case, we can pick elements with indexes $$$1$$$, $$$2$$$ and $$$4$$$ (in $$$0$$$ indexation). For this elements holds: $$$2 \oplus 2 < 4 \oplus 1$$$ and $$$4 \oplus 4 < 1 \oplus 2$$$.


It is the easy version of the problem. The only difference is that in this version $$$a_i \le 200$$$.You are given an array of $$$n$$$ integers $$$a_0, a_1, a_2, \ldots a_{n - 1}$$$. Bryap wants to find the longest beautiful subsequence in the array.An array $$$b = [b_0, b_1, \ldots, b_{m-1}]$$$, where $$$0 \le b_0 < b_1 < \ldots < b_{m - 1} < n$$$, is a subsequence of length $$$m$$$ of the array $$$a$$$.Subsequence $$$b = [b_0, b_1, \ldots, b_{m-1}]$$$ of length $$$m$$$ is called beautiful, if the following condition holds:   For any $$$p$$$ ($$$0 \le p < m - 1$$$) holds: $$$a_{b_p} \oplus b_{p+1} < a_{b_{p+1}} \oplus b_p$$$. Here $$$a \oplus b$$$ denotes the bitwise XOR of $$$a$$$ and $$$b$$$. For example, $$$2 \oplus 4 = 6$$$ and $$$3 \oplus 1=2$$$.Bryap is a simple person so he only wants to know the length of the longest such subsequence. Help Bryap and find the answer to his question.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$)  — the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$2 \leq n \leq 3 \cdot 10^5$$$) — the length of the array. The second line of each test case contains $$$n$$$ integers $$$a_0,a_1,...,a_{n-1}$$$ ($$$0 \leq a_i \leq 200$$$) — the elements of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

NoteIn the first test case, we can pick the whole array as a beautiful subsequence because $$$1 \oplus 1 < 2 \oplus 0$$$.In the second test case, we can pick elements with indexes $$$1$$$, $$$2$$$ and $$$4$$$ (in $$$0$$$-indexation). For this elements holds: $$$2 \oplus 2 < 4 \oplus 1$$$ and $$$4 \oplus 4 < 1 \oplus 2$$$.


The robot is placed in the top left corner of a grid, consisting of $$$n$$$ rows and $$$m$$$ columns, in a cell $$$(1, 1)$$$.In one step, it can move into a cell, adjacent by a side to the current one:   $$$(x, y) \rightarrow (x, y + 1)$$$;  $$$(x, y) \rightarrow (x + 1, y)$$$;  $$$(x, y) \rightarrow (x, y - 1)$$$;  $$$(x, y) \rightarrow (x - 1, y)$$$. The robot can't move outside the grid.The cell $$$(s_x, s_y)$$$ contains a deadly laser. If the robot comes into some cell that has distance less than or equal to $$$d$$$ to the laser, it gets evaporated. The distance between two cells $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$.Print the smallest number of steps that the robot can take to reach the cell $$$(n, m)$$$ without getting evaporated or moving outside the grid. If it's not possible to reach the cell $$$(n, m)$$$, print -1.The laser is neither in the starting cell, nor in the ending cell. The starting cell always has distance greater than $$$d$$$ to the laser.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The only line of each testcase contains five integers $$$n, m, s_x, s_y, d$$$ ($$$2 \le n, m \le 1000$$$; $$$1 \le s_x \le n$$$; $$$1 \le s_y \le m$$$; $$$0 \le d \le n + m$$$) — the size of the grid, the cell that contains the laser and the evaporating distance of the laser. The laser is neither in the starting cell, nor in the ending cell ($$$(s_x, s_y) \neq (1, 1)$$$ and $$$(s_x, s_y) \neq (n, m)$$$). The starting cell $$$(1, 1)$$$ always has distance greater than $$$d$$$ to the laser ($$$|s_x - 1| + |s_y - 1| > d$$$).

For each testcase, print a single integer. If it's possible to reach the cell $$$(n, m)$$$ from $$$(1, 1)$$$ without getting evaporated or moving outside the grid, then print the smallest amount of steps it can take the robot to reach it. Otherwise, print -1.


You have an image file of size $$$2 \times 2$$$, consisting of $$$4$$$ pixels. Each pixel can have one of $$$26$$$ different colors, denoted by lowercase Latin letters.You want to recolor some of the pixels of the image so that all $$$4$$$ pixels have the same color. In one move, you can choose no more than two pixels of the same color and paint them into some other color (if you choose two pixels, both should be painted into the same color).What is the minimum number of moves you have to make in order to fulfill your goal?

The first line contains one integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case consists of two lines. Each of these lines contains two lowercase letters of Latin alphabet without any separators, denoting a row of pixels in the image.

For each test case, print one integer — the minimum number of moves you have to make so that all $$$4$$$ pixels of the image have the same color.

NoteLet's analyze the test cases of the example.In the first test case, you can paint the bottom left pixel and the top right pixel (which share the same color) into the color r, so all pixels have this color.In the second test case, two moves are enough:  paint both top pixels, which have the same color c, into the color b;  paint the bottom left pixel into the color b. In the third test case, all pixels already have the same color.In the fourth test case, you may leave any of the pixels unchanged, and paint all three other pixels into the color of that pixel in three moves.In the fifth test case, you can paint both top pixels into the color x.

5

rb

br

cc

wb

aa

aa

ab

cd

yy

xx


Misha has a square $$$n \times n$$$ matrix, where the number in row $$$i$$$ and column $$$j$$$ is equal to $$$a_{i, j}$$$. Misha wants to modify the matrix to contain exactly $$$k$$$ distinct integers. To achieve this goal, Misha can perform the following operation zero or more times:  choose any square submatrix of the matrix (you choose $$$(x_1,y_1)$$$, $$$(x_2,y_2)$$$, such that $$$x_1 \leq x_2$$$, $$$y_1 \leq y_2$$$, $$$x_2 - x_1 = y_2 - y_1$$$, then submatrix is a set of cells with coordinates $$$(x, y)$$$, such that $$$x_1 \leq x \leq x_2$$$, $$$y_1 \leq y \leq y_2$$$),  choose an integer $$$k$$$, where $$$1 \leq k \leq n^2$$$,  replace all integers in the submatrix with $$$k$$$. Please find the minimum number of operations that Misha needs to achieve his goal.

The first input line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 500, 1 \leq k \leq n^2$$$)  — the size of the matrix and the desired amount of distinct elements in the matrix. Then $$$n$$$ lines follows. The $$$i$$$-th of them contains $$$n$$$ integers $$$a_{i, 1}, a_{i, 2}, \ldots, a_{i, n}$$$ ($$$1 \leq a_{i,j} \leq n^2$$$) — the elements of the $$$i$$$-th row of the matrix.

Output one integer — the minimum number of operations required.

NoteIn the first test case the answer is $$$1$$$, because one can change the value in the bottom right corner of the matrix to $$$1$$$. The resulting matrix can be found below: 111112341 In the second test case the answer is $$$2$$$. First, one can change the entire matrix to contain only $$$1$$$s, and the change the value of any single cell to $$$2$$$. One of the possible resulting matrices is displayed below: 111111112


You are given an array $$$a_1, a_2, \dots, a_n$$$, which is sorted in non-descending order. You decided to perform the following steps to create array $$$b_1, b_2, \dots, b_n$$$:   Create an array $$$d$$$ consisting of $$$n$$$ arbitrary non-negative integers.  Set $$$b_i = a_i + d_i$$$ for each $$$b_i$$$.  Sort the array $$$b$$$ in non-descending order. You are given the resulting array $$$b$$$. For each index $$$i$$$, calculate what is the minimum and maximum possible value of $$$d_i$$$ you can choose in order to get the given array $$$b$$$.Note that the minimum (maximum) $$$d_i$$$-s are independent of each other, i. e. they can be obtained from different possible arrays $$$d$$$.

The first line contains the single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of arrays $$$a$$$, $$$b$$$ and $$$d$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$; $$$a_i \le a_{i+1}$$$) — the array $$$a$$$ in non-descending order. The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$; $$$b_i \le b_{i+1}$$$) — the array $$$b$$$ in non-descending order. Additional constraints on the input:    there is at least one way to obtain the array $$$b$$$ from the $$$a$$$ by choosing an array $$$d$$$ consisting of non-negative integers;  the sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, print two lines. In the first line, print $$$n$$$ integers $$$d_1^{min}, d_2^{min}, \dots, d_n^{min}$$$, where $$$d_i^{min}$$$ is the minimum possible value you can add to $$$a_i$$$. Secondly, print $$$n$$$ integers $$$d_1^{max}, d_2^{max}, \dots, d_n^{max}$$$, where $$$d_i^{max}$$$ is the maximum possible value you can add to $$$a_i$$$. All $$$d_i^{min}$$$ and $$$d_i^{max}$$$ values are independent of each other. In other words, for each $$$i$$$, $$$d_i^{min}$$$ is just the minimum value among all possible values of $$$d_i$$$.


You are given two arrays $$$a$$$ and $$$b$$$, consisting of $$$n$$$ integers each.Let's define a function $$$f(a, b)$$$ as follows:   let's define an array $$$c$$$ of size $$$n$$$, where $$$c_i = a_i \oplus b_i$$$ ($$$\oplus$$$ denotes bitwise XOR);  the value of the function is $$$c_1 \mathbin{\&} c_2 \mathbin{\&} \cdots \mathbin{\&} c_n$$$ (i.e. bitwise AND of the entire array $$$c$$$). Find the maximum value of the function $$$f(a, b)$$$ if you can reorder the array $$$b$$$ in an arbitrary way (leaving the initial order is also an option).

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of arrays $$$a$$$ and $$$b$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i < 2^{30}$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_i < 2^{30}$$$). The sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case print one integer — the maximum value of the function $$$f(a, b)$$$ if you can reorder the array $$$b$$$ in an arbitrary way.


You are given a string $$$s$$$, consisting of lowercase Latin letters.You are asked $$$q$$$ queries about it: given another string $$$t$$$, consisting of lowercase Latin letters, perform the following steps:  concatenate $$$s$$$ and $$$t$$$;  calculate the prefix function of the resulting string $$$s+t$$$;  print the values of the prefix function on positions $$$|s|+1, |s|+2, \dots, |s|+|t|$$$ ($$$|s|$$$ and $$$|t|$$$ denote the lengths of strings $$$s$$$ and $$$t$$$, respectively);  revert the string back to $$$s$$$. The prefix function of a string $$$a$$$ is a sequence $$$p_1, p_2, \dots, p_{|a|}$$$, where $$$p_i$$$ is the maximum value of $$$k$$$ such that $$$k < i$$$ and $$$a[1..k]=a[i-k+1..i]$$$ ($$$a[l..r]$$$ denotes a contiguous substring of a string $$$a$$$ from a position $$$l$$$ to a position $$$r$$$, inclusive). In other words, it's the longest proper prefix of the string $$$a[1..i]$$$ that is equal to its suffix of the same length.

The first line contains a non-empty string $$$s$$$ ($$$1 \le |s| \le 10^6$$$), consisting of lowercase Latin letters. The second line contains a single integer $$$q$$$ ($$$1 \le q \le 10^5$$$) — the number of queries. Each of the next $$$q$$$ lines contains a query: a non-empty string $$$t$$$ ($$$1 \le |t| \le 10$$$), consisting of lowercase Latin letters.

For each query, print the values of the prefix function of a string $$$s+t$$$ on positions $$$|s|+1, |s|+2, \dots, |s|+|t|$$$.


Vasya has a grid with $$$2$$$ rows and $$$n$$$ columns. He colours each cell red, green, or blue.Vasya is colourblind and can't distinguish green from blue. Determine if Vasya will consider the two rows of the grid to be coloured the same.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of columns of the grid. The following two lines each contain a string consisting of $$$n$$$ characters, each of which is either R, G, or B, representing a red, green, or blue cell, respectively — the description of the grid.

For each test case, output "YES" if Vasya considers the grid's two rows to be identical, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

NoteIn the first test case, Vasya sees the second cell of each row as the same because the second cell of the first row is green and the second cell of the second row is blue, so he can't distinguish these two cells. The rest of the rows are equal in colour. Therefore, Vasya will say that the two rows are coloured the same, even though they aren't.In the second test case, Vasya can see that the two rows are different.In the third test case, every cell is green or blue, so Vasya will think they are the same.

6

2

RG

RB

4

GRBG

GBGB

5

GGGGG

BBBBB

7

BBBBBBB

RRRRRRR

8

RGBRRGBR

RGGRRBGR

1

G

G


You are given a bipartite graph with $$$n_1$$$ vertices in the first part, $$$n_2$$$ vertices in the second part, and $$$m$$$ edges. The maximum matching in this graph is the maximum possible (by size) subset of edges of this graph such that no vertex is incident to more than one chosen edge.You have to process two types of queries to this graph:  $$$1$$$ — remove the minimum possible number of vertices from this graph so that the size of the maximum matching gets reduced exactly by $$$1$$$, and print the vertices that you have removed. Then, find any maximum matching in this graph and print the sum of indices of edges belonging to this matching;  $$$2$$$ — query of this type will be asked only after a query of type $$$1$$$. As the answer to this query, you have to print the edges forming the maximum matching you have chosen in the previous query. Note that you should solve the problem in online mode. It means that you can't read the whole input at once. You can read each query only after writing the answer for the last query. Use functions fflush in C++ and BufferedWriter.flush in Java languages after each writing in your program.

The first line contains four integers $$$n_1$$$, $$$n_2$$$, $$$m$$$ and $$$q$$$ ($$$1 \le n_1, n_2 \le 2 \cdot 10^5$$$; $$$1 \le m \le \min(n_1 \cdot n_2, 2 \cdot 10^5)$$$; $$$1 \le q \le 2 \cdot 10^5$$$). Then $$$m$$$ lines follow. The $$$i$$$-th of them contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i \le n_1$$$; $$$1 \le y_i \le n_2$$$) meaning that the $$$i$$$-th edge connects the vertex $$$x_i$$$ in the first part and the vertex $$$y_i$$$ in the second part. There are no pairs of vertices that are connected by more than one edge. Then $$$q$$$ lines follow. The $$$i$$$-th of them contains one integer, $$$1$$$ or $$$2$$$, denoting the $$$i$$$-th query. Additional constraints on queries:   the number of queries of type $$$1$$$ won't exceed the size of the maximum matching in the initial graph;  the number of queries of type $$$2$$$ won't exceed $$$3$$$;  each query of type $$$2$$$ is preceded by a query of type $$$1$$$;  your solution is allowed to read the $$$i$$$-th query only after printing the answer for the $$$(i-1)$$$-th query and flushing the output.

For a query of type $$$1$$$, print the answer in three lines as follows:   the first line should contain the number of vertices you remove;  the second line should contain the indices of vertices you remove, as follows: if you remove the vertex $$$x$$$ from the left part, print $$$x$$$; if you remove the vertex $$$y$$$ from the right part, print $$$-y$$$ (negative index);  the third line should contain the sum of indices of edges in some maximum matching in the resulting graph. The edges are numbered from $$$1$$$ to $$$m$$$.  For a query of type $$$2$$$, print the answer in two lines as follows:   the first line should contain the size of the maximum matching;  the second line should contain the indices of the edges belonging to the maximum matching. Note that the sum of these indices should be equal to the number you printed at the end of the previous query of type $$$1$$$;  After printing the answer to a query, don't forget to flush the output.

NoteIn this problem, you may receive the verdict "Idleness Limit Exceeded" since it is in online mode. If it happens, it means that either the output format is wrong, or you don't meet some constraint of the problem. You may treat this verdict as "Wrong Answer".For your convenience, the output for queries in the example is separated by the line ===. Don't print this line in your program, it is done only to make sure that it's easy to distinguish between answers for different queries in the statement.


Timur likes his name. As a spelling of his name, he allows any permutation of the letters of the name. For example, the following strings are valid spellings of his name: Timur, miurT, Trumi, mriTu. Note that the correct spelling must have uppercased T and lowercased other letters.Today he wrote string $$$s$$$ of length $$$n$$$ consisting only of uppercase or lowercase Latin letters. He asks you to check if $$$s$$$ is the correct spelling of his name.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 10^3$$$) — the number of test cases. The first line of each test case contains an integer $$$n$$$ $$$(1 \leq n \leq 10)$$$ — the length of string $$$s$$$. The second line of each test case contains a string $$$s$$$ consisting of only uppercase or lowercase Latin characters.

For each test case, output "YES" (without quotes) if $$$s$$$ satisfies the condition, and "NO" (without quotes) otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).

10

5

Timur

5

miurT

5

Trumi

5

mriTu

5

timur

4

Timr

6

Timuur

10

codeforces

10

TimurTimur

5

TIMUR


There are $$$n$$$ people in a horizontal line, each looking either to the left or the right. Each person counts the number of people in the direction they are looking. The value of the line is the sum of each person's count.For example, in the arrangement LRRLL, where L stands for a person looking left and R stands for a person looking right, the counts for each person are $$$[0, 3, 2, 3, 4]$$$, and the value is $$$0+3+2+3+4=12$$$.You are given the initial arrangement of people in the line. For each $$$k$$$ from $$$1$$$ to $$$n$$$, determine the maximum value of the line if you can change the direction of at most $$$k$$$ people.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 2\cdot10^5$$$) — the length of the line. The following line contains a string consisting of $$$n$$$ characters, each of which is either L or R, representing a person facing left or right, respectively — the description of the line. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$. Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

For each test case, output $$$n$$$ space-separated non-negative integers — the maximum value of the line if you can change the direction of at most $$$k$$$ people for each $$$k$$$ from $$$1$$$ to $$$n$$$, inclusive.

NoteIn the first test case:   $$$k=1$$$: change the direction of $$$1$$$ person to make the line RLR. The total value is $$$2+1+0=3$$$.  $$$k=2$$$: change the direction of $$$2$$$ people to make the line RLL. The total value is $$$2+1+2=5$$$.  $$$k=3$$$: change the direction of $$$2$$$ people to make the line RLL. The total value is $$$2+1+2=5$$$. Note that you have to change the direction of at most $$$k$$$ people. In the second test case, it is optimal to only change the direction of the first person for all $$$k$$$ from $$$1$$$ to $$$5$$$ (that is, make the line RRRLL).

6

3

LLR

5

LRRLL

1

L

12

LRRRLLLRLLRL

10

LLLLLRRRRR

9

LRLRLRLRL


You have $$$n$$$ rectangles, the $$$i$$$-th rectangle has height $$$h_i$$$ and width $$$w_i$$$.You are asked $$$q$$$ queries of the form $$$h_s \ w_s \ h_b \ w_b$$$. For each query output, the total area of rectangles you own that can fit a rectangle of height $$$h_s$$$ and width $$$w_s$$$ while also fitting in a rectangle of height $$$h_b$$$ and width $$$w_b$$$. In other words, print $$$\sum h_i \cdot w_i$$$ for $$$i$$$ such that $$$h_s < h_i < h_b$$$ and $$$w_s < w_i < w_b$$$. Please note, that if two rectangles have the same height or the same width, then they cannot fit inside each other. Also note that you cannot rotate rectangles.Please note that the answer for some test cases won't fit into 32-bit integer type, so you should use at least 64-bit integer type in your programming language (like long long for C++).

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The first line of each test case two integers $$$n, q$$$ ($$$1 \leq n \leq 10^5$$$; $$$1 \leq q \leq 10^5$$$) — the number of rectangles you own and the number of queries. Then $$$n$$$ lines follow, each containing two integers $$$h_i, w_i$$$ ($$$1 \leq h_i, w_i \leq 1000$$$) — the height and width of the $$$i$$$-th rectangle. Then $$$q$$$ lines follow, each containing four integers $$$h_s, w_s, h_b, w_b$$$ ($$$1 \leq h_s < h_b,\ w_s < w_b \leq 1000$$$) — the description of each query. The sum of $$$q$$$ over all test cases does not exceed $$$10^5$$$, and the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, output $$$q$$$ lines, the $$$i$$$-th line containing the answer to the $$$i$$$-th query.

Note  In the first test case, there is only one query. We need to find the sum of areas of all rectangles that can fit a $$$1 \times 1$$$ rectangle inside of it and fit into a $$$3 \times 4$$$ rectangle.Only the $$$2 \times 3$$$ rectangle works, because $$$1 < 2$$$ (comparing heights) and $$$1 < 3$$$ (comparing widths), so the $$$1 \times 1$$$ rectangle fits inside, and $$$2 < 3$$$ (comparing heights) and $$$3 < 4$$$ (comparing widths), so it fits inside the $$$3 \times 4$$$ rectangle. The $$$3 \times 2$$$ rectangle is too tall to fit in a $$$3 \times 4$$$ rectangle. The total area is $$$2 \cdot 3 = 6$$$.


An L-shape is a figure on gridded paper that looks like the first four pictures below. An L-shape contains exactly three shaded cells (denoted by *), which can be rotated in any way.  You are given a rectangular grid. Determine if it contains L-shapes only, where L-shapes can't touch an edge or corner. More formally:   Each shaded cell in the grid is part of exactly one L-shape, and  no two L-shapes are adjacent by edge or corner. For example, the last two grids in the picture above do not satisfy the condition because the two L-shapes touch by corner and edge, respectively.

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 50$$$) — the number of rows and columns in the grid, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either '.' or '*' — an empty cell or a shaded cell, respectively.

For each test case, output "YES" if the grid is made up of L-shape that don't share edges or corners, and "NO" otherwise. You can output the answer in any case (for example, the strings "yEs", "yes", "Yes" and "YES" will be recognized as a positive answer).


Three guys play a game: first, each person writes down $$$n$$$ distinct words of length $$$3$$$. Then, they total up the number of points as follows:   if a word was written by one person — that person gets 3 points,  if a word was written by two people — each of the two gets 1 point,  if a word was written by all — nobody gets any points.  In the end, how many points does each player have?

The input consists of multiple test cases. The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 100$$$) — the number of test cases. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \leq n \leq 1000$$$) — the number of words written by each person. The following three lines each contain $$$n$$$ distinct strings — the words written by each person. Each string consists of $$$3$$$ lowercase English characters.

For each test case, output three space-separated integers — the number of points each of the three guys earned. You should output the answers in the same order as the input; the $$$i$$$-th integer should be the number of points earned by the $$$i$$$-th guy.

NoteIn the first test case:   The word $$$\texttt{abc}$$$ was written by the first and third guys — they each get $$$1$$$ point.  The word $$$\texttt{def}$$$ was written by the second guy only — he gets $$$3$$$ points.

3

1

abc

def

abc

3

orz for qaq

qaq orz for

cod for ces

5

iat roc hem ica lly

bac ter iol ogi sts

bac roc lly iol iat


Given an integer $$$n$$$, find any array $$$a$$$ of $$$n$$$ distinct nonnegative integers less than $$$2^{31}$$$ such that the bitwise XOR of the elements on odd indices equals the bitwise XOR of the elements on even indices.

The first line of the input contains an integer $$$t$$$ ($$$1 \leq t \leq 629$$$) — the number of test cases. Then $$$t$$$ lines follow, each containing a single integer $$$n$$$ $$$(3 \leq n \leq 2\cdot10^5)$$$ — the length of the array. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

For each test case, output one line containing $$$n$$$ distinct integers that satisfy the conditions. If there are multiple answers, you can output any of them.

NoteIn the first test case the XOR on odd indices is $$$4 \oplus 1 \oplus 0 \oplus 7 = 2$$$ and the XOR on even indices is $$$2 \oplus 5 \oplus 6 \oplus 3= 2$$$.


Pak Chanek has a grid that has $$$N$$$ rows and $$$M$$$ columns. Each row is numbered from $$$1$$$ to $$$N$$$ from top to bottom. Each column is numbered from $$$1$$$ to $$$M$$$ from left to right.Each tile in the grid contains a number. The numbers are arranged as follows:   Row $$$1$$$ contains integers from $$$1$$$ to $$$M$$$ from left to right.  Row $$$2$$$ contains integers from $$$M+1$$$ to $$$2 \times M$$$ from left to right.  Row $$$3$$$ contains integers from $$$2 \times M+1$$$ to $$$3 \times M$$$ from left to right.  And so on until row $$$N$$$. A domino is defined as two different tiles in the grid that touch by their sides. A domino is said to be tight if and only if the two numbers in the domino have a difference of exactly $$$1$$$. Count the number of distinct tight dominoes in the grid.Two dominoes are said to be distinct if and only if there exists at least one tile that is in one domino, but not in the other.

The only line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \leq N, M \leq 10^9$$$) — the number of rows and columns in the grid.

An integer representing the number of distinct tight dominoes in the grid.

NoteThe picture below is the grid that Pak Chanek has in the first example.  The picture below is an example of a tight domino in the grid.


Pak Chanek has a mirror in the shape of a circle. There are $$$N$$$ lamps on the circumference numbered from $$$1$$$ to $$$N$$$ in clockwise order. The length of the arc from lamp $$$i$$$ to lamp $$$i+1$$$ is $$$D_i$$$ for $$$1 \leq i \leq N-1$$$. Meanwhile, the length of the arc between lamp $$$N$$$ and lamp $$$1$$$ is $$$D_N$$$.Pak Chanek wants to colour the lamps with $$$M$$$ different colours. Each lamp can be coloured with one of the $$$M$$$ colours. However, there cannot be three different lamps such that the colours of the three lamps are the same and the triangle made by considering the three lamps as vertices is a right triangle (triangle with one of its angles being exactly $$$90$$$ degrees).The following are examples of lamp colouring configurations on the circular mirror. Figure 1. an example of an incorrect colouring because lamps $$$1$$$, $$$2$$$, and $$$3$$$ form a right triangleFigure 2. an example of a correct colouringFigure 3. an example of a correct colouring Before colouring the lamps, Pak Chanek wants to know the number of distinct colouring configurations he can make. Count the number of distinct possible lamp colouring configurations, modulo $$$998\,244\,353$$$.

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$1 \le N \le 3 \cdot 10^5$$$, $$$2 \le M \le 3 \cdot 10^5$$$) — the number of lamps in the mirror and the number of different colours used. The second line contains $$$N$$$ integers $$$D_1, D_2, \ldots, D_N$$$ ($$$1 \le D_i \le 10^9$$$) — the lengths of the arcs between the lamps in the mirror.

An integer representing the number of possible lamp colouring configurations, modulo $$$998\,244\,353$$$.


A basketball competition is held where the number of players in a team does not have a maximum or minimum limit (not necessarily $$$5$$$ players in one team for each match). There are $$$N$$$ candidate players in the competition that will be trained by Pak Chanek, the best basketball coach on earth. The $$$i$$$-th candidate player has a power of $$$P_i$$$.Pak Chanek will form zero or more teams from the $$$N$$$ candidate players on the condition that each candidate player may only join in at most one team. Each of Pak Chanek's teams will be sent to compete once with an enemy team that has a power of $$$D$$$. In each match, the team sent is said to defeat the enemy team if the sum of powers from the formed players is strictly greater than $$$D$$$.One of Pak Chanek's skills is that when a team that has been formed plays in a match, he can change the power of each player in the team to be equal to the biggest player power from the team.Determine the maximum number of wins that can be achieved by Pak Chanek.

The first line contains two integers $$$N$$$ and $$$D$$$ ($$$1 \le N \le 10^5$$$, $$$1 \le D \le 10^9$$$) — the number of candidate players and the power of the enemy team. The second line contains $$$N$$$ integers $$$P_1, P_2, \ldots, P_N$$$ ($$$1 \le P_i \le 10^9$$$) — the powers of all candidate players.

A line containing an integer representing the maximum number of wins that can be achieved by Pak Chanek.

NoteThe $$$1$$$-st team formed is a team containing players $$$4$$$ and $$$6$$$. The power of each player in the team becomes $$$100$$$. So the total power of the team is $$$100 + 100 = 200 > 180$$$.The $$$2$$$-nd team formed is a team containing players $$$1$$$, $$$2$$$, and $$$5$$$. The power of each player in the team becomes $$$90$$$. So the total power of the team is $$$90 + 90 + 90 = 270 > 180$$$.


Let's say Pak Chanek has an array $$$A$$$ consisting of $$$N$$$ positive integers. Pak Chanek will do a number of operations. In each operation, Pak Chanek will do the following:   Choose an index $$$p$$$ ($$$1 \leq p \leq N$$$).  Let $$$c$$$ be the number of operations that have been done on index $$$p$$$ before this operation.  Decrease the value of $$$A_p$$$ by $$$2^c$$$.  Multiply the value of $$$A_p$$$ by $$$2$$$. After each operation, all elements of $$$A$$$ must be positive integers.An array $$$A$$$ is said to be sortable if and only if Pak Chanek can do zero or more operations so that $$$A_1 < A_2 < A_3 < A_4 < \ldots < A_N$$$.Pak Chanek must find an array $$$A$$$ that is sortable with length $$$N$$$ such that $$$A_1 + A_2 + A_3 + A_4 + \ldots + A_N$$$ is the minimum possible. If there are more than one possibilities, Pak Chanek must choose the array that is lexicographically minimum among them.Pak Chanek must solve the following things:   Pak Chanek must print the value of $$$A_1 + A_2 + A_3 + A_4 + \ldots + A_N$$$ for that array.  $$$Q$$$ questions will be given. For the $$$i$$$-th question, an integer $$$P_i$$$ is given. Pak Chanek must print the value of $$$A_{P_i}$$$. Help Pak Chanek solve the problem.Note: an array $$$B$$$ of size $$$N$$$ is said to be lexicographically smaller than an array $$$C$$$ that is also of size $$$N$$$ if and only if there exists an index $$$i$$$ such that $$$B_i < C_i$$$ and for each $$$j < i$$$, $$$B_j = C_j$$$.

The first line contains two integers $$$N$$$ and $$$Q$$$ ($$$1 \leq N \leq 10^9$$$, $$$0 \leq Q \leq \min(N, 10^5)$$$) — the required length of array $$$A$$$ and the number of questions. The $$$i$$$-th of the next $$$Q$$$ lines contains a single integer $$$P_i$$$ ($$$1 \leq P_1 < P_2 < \ldots < P_Q \leq N$$$) — the index asked in the $$$i$$$-th question.

Print $$$Q+1$$$ lines. The $$$1$$$-st line contains an integer representing $$$A_1 + A_2 + A_3 + A_4 + \ldots + A_N$$$. For each $$$1 \leq i \leq Q$$$, the $$$(i+1)$$$-th line contains an integer representing $$$A_{P_i}$$$.

NoteIn the first example, the array $$$A$$$ obtained is $$$[1, 2, 3, 3, 4, 4]$$$. We can see that the array is sortable by doing the following operations:   Choose index $$$5$$$, then $$$A = [1, 2, 3, 3, 6, 4]$$$.  Choose index $$$6$$$, then $$$A = [1, 2, 3, 3, 6, 6]$$$.  Choose index $$$4$$$, then $$$A = [1, 2, 3, 4, 6, 6]$$$.  Choose index $$$6$$$, then $$$A = [1, 2, 3, 4, 6, 8]$$$.


In the country of Dengkleknesia, there are $$$N$$$ factories numbered from $$$1$$$ to $$$N$$$. Factory $$$i$$$ has an electrical coefficient of $$$A_i$$$. There are also $$$N-1$$$ power lines with the $$$j$$$-th power line connecting factory $$$U_j$$$ and factory $$$V_j$$$. It can be guaranteed that each factory in Dengkleknesia is connected to all other factories in Dengkleknesia through one or more power lines. In other words, the collection of factories forms a tree. Each pair of different factories in Dengkleknesia can use one or more existing power lines to transfer electricity to each other. However, each power line needs to be turned on first so that electricity can pass through it.Define $$$f(x, y, z)$$$ as the minimum number of power lines that need to be turned on so that factory $$$x$$$ can make electrical transfers to factory $$$y$$$ and factory $$$z$$$. Also define $$$g(x, y, z)$$$ as the number of distinct prime factors of $$$\text{GCD}(A_x, A_y, A_z)$$$.To measure the electrical efficiency, you must find the sum of $$$f(x, y, z) \times g(x, y, z)$$$ for all combinations of $$$(x, y, z)$$$ such that $$$1 \leq x < y < z \leq N$$$. Because the answer can be very large, you just need to output the answer modulo $$$998\,244\,353$$$.Note: $$$\text{GCD}(k_1, k_2, k_3)$$$ is the greatest common divisor of $$$k_1$$$, $$$k_2$$$, and $$$k_3$$$, which is the biggest integer that simultaneously divides $$$k_1$$$, $$$k_2$$$, and $$$k_3$$$.

The first line contains a single integer $$$N$$$ ($$$1 \le N \le 2 \cdot 10^5$$$) — the number of factories in Dengkleknesia. The second line contains $$$N$$$ integers $$$A_1, A_2, \dots, A_N$$$ ($$$1 \leq A_i \leq 2 \cdot 10^5$$$) — the electrical coefficients of the factories. The $$$j$$$-th of the next $$$N-1$$$ lines contains two integers $$$U_j$$$ and $$$V_j$$$ ($$$1 \le U_j, V_j \le N$$$) — a power line that connects cities $$$U_j$$$ and $$$V_j$$$. The collection of factories forms a tree.

An integer representing the sum of $$$f(x, y, z) \times g(x, y, z)$$$ for all combinations of $$$(x, y, z)$$$ such that $$$1 \leq x < y < z \leq N$$$, modulo $$$998\,244\,353$$$

NoteIn the first example, the only $$$(x, y, z)$$$ possible is $$$(1, 2, 3)$$$. Because $$$\text{GCD}(A_1, A_2, A_3) = \text{GCD}(1, 2, 3) = 1$$$ has $$$0$$$ distinct prime factors, therefore $$$f(x, y, z) \times g(x, y, z) = 2 \times 0 = 0$$$.In the second example, all triples $$$(x, y, z)$$$ that satisfy the condition are as follows:   $$$(1, 2, 3) \rightarrow f(1, 2, 3) \times g(1, 2, 3) = 2 \times 1 = 2$$$  $$$(1, 2, 4) \rightarrow f(1, 2, 4) \times g(1, 2, 4) = 2 \times 1 = 2$$$  $$$(1, 3, 4) \rightarrow f(1, 3, 4) \times g(1, 3, 4) = 3 \times 2 = 6$$$  $$$(2, 3, 4) \rightarrow f(2, 3, 4) \times g(2, 3, 4) = 2 \times 1 = 2$$$ So the electrical efficiency is $$$2 + 2 + 6 + 2 = 12$$$.


Pak Chanek is traveling to Manado. It turns out that OSN (Indonesian National Scientific Olympiad) 2019 is being held. The contestants of OSN 2019 are currently lining up in a field to be photographed. The field is shaped like a grid of size $$$N \times 10^{100}$$$ with $$$N$$$ rows and $$$10^{100}$$$ columns. The rows are numbered from $$$1$$$ to $$$N$$$ from north to south, the columns are numbered from $$$1$$$ to $$$10^{100}$$$ from west to east. The tile in row $$$r$$$ and column $$$c$$$ is denoted as $$$(r,c)$$$.There are $$$N$$$ provinces that participate in OSN 2019. Initially, each contestant who represents province $$$i$$$ stands in tile $$$(i, p)$$$ for each $$$p$$$ satisfying $$$L_i \leq p \leq R_i$$$. So, we can see that there are $$$R_i-L_i+1$$$ contestants who represent province $$$i$$$.Pak Chanek has a variable $$$Z$$$ that is initially equal to $$$0$$$. In one operation, Pak Chanek can choose a row $$$i$$$ and a positive integer $$$k$$$. Then, Pak Chanek will do one of the two following possibilities:   Move all contestants in row $$$i$$$ exactly $$$k$$$ tiles to the west. In other words, a contestant who is in $$$(i, p)$$$ is moved to $$$(i, p-k)$$$.  Move all contestants in row $$$i$$$ exactly $$$k$$$ tiles to the east. In other words, a contestant who is in $$$(i, p)$$$ is moved to $$$(i, p+k)$$$. After each operation, the value of $$$Z$$$ will change into $$$Z \text{ OR } k$$$, with $$$\text{OR}$$$ being the bitwise OR operation. Note that Pak Chanek can do operations to the same row more than once. Also note that Pak Chanek is not allowed to move contestants out of the grid.There are $$$Q$$$ questions. For the $$$j$$$-th question, you are given a positive integer $$$W_j$$$, Pak Chanek must do zero or more operations so that the final value of $$$Z$$$ is exactly $$$W_j$$$. Define $$$M$$$ as the biggest number such that after all operations, there is at least one column that contains exactly $$$M$$$ contestants. For each question, you must find the biggest possible $$$M$$$ for all sequences of operations that can be done by Pak Chanek. Note that the operations done by Pak Chanek for one question do not carry over to other questions.

The first line contains a single integer $$$N$$$ ($$$1 \leq N \leq 10^5$$$) — the number of rows in the grid and also the number of provinces that participate in OSN 2019. The $$$i$$$-th of the next $$$N$$$ lines contains two integers $$$L_i$$$ and $$$R_i$$$ ($$$1 \leq L_i \leq R_i \leq 10^9$$$) describing the positions of the contestants who represent province $$$i$$$. The next line contains a single integer $$$Q$$$ ($$$1 \leq Q \leq 10^5$$$) — the number of questions. The $$$j$$$-th of the next $$$Q$$$ lines contains a single integer $$$W_j$$$ ($$$1 \leq W_j \leq 10^9$$$) — the required final value of $$$Z$$$ for the $$$j$$$-th question.

Output $$$Q$$$ lines, with the $$$j$$$-th line containing an integer that is the answer to the $$$j$$$-th question.

NoteFor the $$$1$$$-st question, Pak Chanek can do the following operations to get $$$M=2$$$:   Move all contestants in row $$$2$$$ to the east by $$$4$$$ tiles. $$$Z$$$ changes into $$$0 \text{ OR } 4 = 4$$$.  Move all contestants in row $$$1$$$ to the east by $$$12$$$ tiles. $$$Z$$$ changes into $$$4 \text{ OR } 12 = 12$$$. Now, columns $$$14$$$ and $$$15$$$ each contains exactly $$$2$$$ contestants.For the $$$2$$$-nd question, Pak Chanek can do the following operations to get $$$M=3$$$:   Move all contestants in row $$$3$$$ to the east by $$$4$$$ tiles. $$$Z$$$ changes into $$$0 \text{ OR } 4 = 4$$$.  Move all contestants in row $$$3$$$ to the west by $$$1$$$ tiles. $$$Z$$$ changes into $$$4 \text{ OR } 1 = 5$$$.  Move all contestants in row $$$1$$$ to the east by $$$5$$$ tiles. $$$Z$$$ changes into $$$5 \text{ OR } 5 = 5$$$.  Move all contestants in row $$$1$$$ to the east by $$$5$$$ tiles. $$$Z$$$ changes into $$$5 \text{ OR } 5 = 5$$$. Now, column $$$11$$$ contains exactly $$$3$$$ contestants.The following is an illustration of the example operations for the $$$2$$$-nd question.


One day, you are accepted as being Dr. Chanek's assistant. The first task given by Dr. Chanek to you is to take care and store his magical stones.Dr. Chanek has $$$N$$$ magical stones with $$$N$$$ being an even number. Those magical stones are numbered from $$$1$$$ to $$$N$$$. Magical stone $$$i$$$ has a strength of $$$A_i$$$. A magical stone can be painted with two colours, namely the colour black or the colour white. You are tasked to paint the magical stones with the colour black or white and store the magical stones into a magic box with a magic coefficient $$$Z$$$ ($$$0 \leq Z \leq 2$$$). The painting of the magical stones must be done in a way such that there are $$$\frac{N}{2}$$$ black magical stones and $$$\frac{N}{2}$$$ white magical stones.Define $$$\text{concat}(x, y)$$$ for two integers $$$x$$$ and $$$y$$$ as the result of concatenating the digits of $$$x$$$ to the left of $$$y$$$ in their decimal representation without changing the order. As an example, $$$\text{concat}(10, 24)$$$ will result in $$$1024$$$.For a magic box with a magic coefficient $$$Z$$$, magical stone $$$i$$$ will react with magical stone $$$j$$$ if the colours of both stones are different and $$$\text{concat}(A_i, A_j) \times \text{concat}(A_j, A_i) + A_i \times A_j \equiv Z \mod 3$$$. A magical stone that is reacting will be very hot and dangerous. Because of that, you must colour the magical stones and determine the magic coefficient $$$Z$$$ of the magic box in a way such that there is no magical stone that reacts, or report if it is impossible.

The first line contains a single even integer $$$N$$$ ($$$2 \le N \le 10^5$$$) — the number of magical stones Dr. Chanek has. The second line contains $$$N$$$ integer $$$A_1, A_2, \ldots, A_N$$$ ($$$1 \leq A_i \leq 10^9$$$) — the strengths of all magical stones.

If it is not possible to satisfy the condition of the problem, output $$$-1$$$. Otherwise, output two lines. The first line contains an integer $$$Z$$$ denoting the magic coefficient of the magic box. The second line contains a string $$$S$$$ of length $$$N$$$. $$$S_i$$$ is $$$0$$$ if magical stone $$$i$$$ is coloured black or $$$1$$$ if magical stone $$$i$$$ is coloured white. If there are more than one possibilities of colouring and choosing the magic coefficient $$$Z$$$, output any of them.

NoteBy giving the above colouring, it can be seen that:   $$$i=1, j=2 \longrightarrow \text{concat}(4, 10) \times \text{concat}(10, 4) + 10 \times 4 = 410 \times 104 + 40 = 42680 \equiv 2 \mod 3$$$  $$$i=1, j=3 \longrightarrow \text{concat}(4, 9) \times \text{concat}(9, 4) + 4 \times 9 = 49 \times 94 + 36 = 4642 \equiv 1 \mod 3$$$  $$$i=4, j=2 \longrightarrow \text{concat}(14, 10) \times \text{concat}(10, 14) + 10 \times 14 = 1410 \times 1014 + 140 = 1429880 \equiv 2 \mod 3$$$  $$$i=4, j=3 \longrightarrow \text{concat}(14, 9) \times \text{concat}(9, 14) + 14 \times 9 = 149 \times 914 + 126 = 136312 \equiv 1 \mod 3$$$ Because of that, by choosing $$$Z = 0$$$, it can be guaranteed that there is no magical stone that reacts.


Pak Chanek plans to build a garage. He wants the garage to consist of a square and a right triangle that are arranged like the following illustration.  Define $$$a$$$ and $$$b$$$ as the lengths of two of the sides in the right triangle as shown in the illustration. An integer $$$x$$$ is suitable if and only if we can construct a garage with assigning positive integer values for the lengths $$$a$$$ and $$$b$$$ ($$$a<b$$$) so that the area of the square at the bottom is exactly $$$x$$$. As a good friend of Pak Chanek, you are asked to help him find the $$$N$$$-th smallest suitable number.

The only line contains a single integer $$$N$$$ ($$$1 \leq N \leq 10^9$$$).

An integer that represents the $$$N$$$-th smallest suitable number.

NoteThe $$$3$$$-rd smallest suitable number is $$$7$$$. A square area of $$$7$$$ can be obtained by assigning $$$a=3$$$ and $$$b=4$$$.


Pak Chanek has a tree called the key tree. This tree consists of $$$N$$$ vertices and $$$N-1$$$ edges. The edges of the tree are numbered from $$$1$$$ to $$$N-1$$$ with edge $$$i$$$ connecting vertices $$$U_i$$$ and $$$V_i$$$. Initially, each edge of the key tree does not have a weight.Formally, a path with length $$$k$$$ in a graph is a sequence $$$[v_1, e_1, v_2, e_2, v_3, e_3, \ldots, v_k, e_k, v_{k+1}]$$$ such that:   For each $$$i$$$, $$$v_i$$$ is a vertex and $$$e_i$$$ is an edge.  For each $$$i$$$, $$$e_i$$$ connects vertices $$$v_i$$$ and $$$v_{i+1}$$$. A circuit is a path that starts and ends on the same vertex.A path in a graph is said to be simple if and only if the path does not use the same edge more than once. Note that a simple path can use the same vertex more than once.The cost of a simple path in a weighted graph is defined as the maximum weight of all edges it traverses.Count the number of distinct undirected weighted graphs that satisfy the following conditions:   The graph has $$$N$$$ vertices and $$$2N-2$$$ edges.  For each pair of different vertices $$$(x, y)$$$, there exists a simple circuit that goes through vertices $$$x$$$ and $$$y$$$ in the graph.  The weight of each edge in the graph is an integer between $$$1$$$ and $$$2N-2$$$ inclusive. Each edge has distinct weights.  The graph is formed in a way such that there is a way to assign a weight $$$W_i$$$ to each edge $$$i$$$ in the key tree that satisfies the following conditions:   For each pair of edges $$$(i, j)$$$, if $$$i<j$$$, then $$$W_i<W_j$$$.  For each pair of different vertex indices $$$(x, y)$$$, the cost of the only simple path from vertex $$$x$$$ to $$$y$$$ in the key tree is equal to the minimum cost of a simple circuit that goes through vertices $$$x$$$ and $$$y$$$ in the graph.   Note that the graph is allowed to have multi-edges, but is not allowed to have self-loops. Print the answer modulo $$$998\,244\,353$$$.Two graphs are considered distinct if and only if there exists a triple $$$(a, b, c)$$$ such that there exists an edge that connects vertices $$$a$$$ and $$$b$$$ with weight $$$c$$$ in one graph, but not in the other.

The first line contains a single integer $$$N$$$ ($$$2 \le N \le 10^5$$$) — the number of vertices in the key tree. The $$$i$$$-th of the next $$$N-1$$$ lines contains two integers $$$U_i$$$ and $$$V_i$$$ ($$$1 \le U_i, V_i \le N$$$) — an edge connecting vertices $$$U_i$$$ and $$$V_i$$$. The graph in the input is a tree.

An integer representing the number of distinct undirected weighted graphs that satisfy the conditions of the problem modulo $$$998\,244\,353$$$.

NoteThe following is an example of a graph that satisfies.The following is an assignment of edge weights in the key tree that corresponds to the graph above.As an example, consider a pair of vertex indices $$$(1, 4)$$$.   The circuit in the graph for this pair of vertices is $$$3 \xrightarrow{2} 2 \xrightarrow{4} 4 \xrightarrow{6} 2 \xrightarrow{1} 1 \xrightarrow{5} 3$$$ with a cost of $$$6$$$.  The path in the key tree for this pair of vertices is $$$1 \xrightarrow{5} 3 \xrightarrow{6} 4$$$ with a cost of $$$6$$$.


One day, Pak Chanek who is already bored of being alone at home decided to go traveling. While looking for an appropriate place, he found that Londonesia has an interesting structure.According to the information gathered by Pak Chanek, there are $$$N$$$ cities numbered from $$$1$$$ to $$$N$$$. The cities are connected to each other with $$$N-1$$$ two-directional roads, with the $$$i$$$-th road connecting cities $$$U_i$$$ and $$$V_i$$$, and taking a time of $$$W_i$$$ hours to be traversed. In other words, Londonesia's structure forms a tree.Pak Chanek wants to go on a journey in Londonesia starting and ending in any city (not necessarily the same city) such that each city is visited at least once with the least time possible. In order for the journey to end quicker, Pak Chanek also carries an instant teleportation device for moving from one city to any city that can only be used at most once. Help Pak Chanek for finding the minimum time needed.Notes:   Pak Chanek only needs to visit each city at least once. Pak Chanek does not have to traverse each road.  In the journey, a city or a road can be visited more than once.

The first line contains a single integer $$$N$$$ ($$$1 \le N \le 10^5$$$) — the number of cities in Londonesia. The $$$i$$$-th of the next $$$N-1$$$ lines contains three integers $$$U_i$$$, $$$V_i$$$, and $$$W_i$$$ ($$$1 \le U_i, V_i \le N$$$, $$$1 \le W_i \le 10^9$$$) — a two-directional road that connects cities $$$U_i$$$ and $$$V_i$$$ that takes $$$W_i$$$ hours to be traversed. The roads in Londonesia form a tree.

Output one integer, which represents the minimum time in hours that is needed to visit each city at least once.

NoteIn the first example, the journey that has the minimum time is $$$2 → 1 \xrightarrow{\text{teleport}} 4 → 3$$$.In the second example, the journey that has the minimum time is $$$3 → 1 → 4 → 1 → 2 \xrightarrow{\text{teleport}} 5$$$.


Pak Chanek is visiting a kingdom that earned a nickname "Kingdom of Criticism" because of how often its residents criticise each aspect of the kingdom. One aspect that is often criticised is the heights of the buildings. The kingdom has $$$N$$$ buildings. Initially, building $$$i$$$ has a height of $$$A_i$$$ units.At any point in time, the residents can give a new criticism, namely they currently do not like buildings with heights between $$$l$$$ and $$$r$$$ units inclusive for some two integers $$$l$$$ and $$$r$$$. It is known that $$$r-l$$$ is always odd.In $$$1$$$ minute, the kingdom's construction team can increase or decrease the height of any building by $$$1$$$ unit as long as the height still becomes a positive number. Each time they receive the current criticism from the residents, the kingdom's construction team makes it so that there are no buildings with heights between $$$l$$$ and $$$r$$$ units inclusive in the minimum time possible. It can be obtained that there is only one way to do this. Note that the construction team only cares about the current criticism from the residents. All previous criticisms are forgotten.There will be $$$Q$$$ queries that you must solve. Each query is one of the three following possibilities:   1 k w: The kingdom's construction team changes the height of building $$$k$$$ to be $$$w$$$ units ($$$1 \leq k \leq N$$$, $$$1 \leq w \leq 10^9$$$).  2 k: The kingdom's construction team wants you to find the height of building $$$k$$$ ($$$1 \leq k \leq N$$$).  3 l r: The residents currently do not like buildings with heights between $$$l$$$ and $$$r$$$ units inclusive ($$$2 \leq l \leq r \leq 10^9-1$$$, $$$r-l$$$ is odd). Note that each change in height still persists to the next queries.

The first line contains a single integer $$$N$$$ ($$$1 \leq N \leq 4 \cdot 10^5$$$) — the number buildings in the kingdom. The second line contains $$$N$$$ integers $$$A_1, A_2, \ldots, A_N$$$ ($$$1 \leq A_i \leq 10^9$$$) — the initial heights of the buildings. The next line contains a single integer $$$Q$$$ ($$$1 \leq Q \leq 4 \cdot 10^5$$$) — the number of queries. The $$$j$$$-th of the next $$$Q$$$ lines contains the $$$j$$$-th query as described. There is at least one query of type $$$2$$$.

For each query of type $$$2$$$, output a line containing an integer representing the height of the building asked.

NoteAfter the $$$1$$$-st query, the height of each building is $$$2, 6, 5, 6, 10$$$.After the $$$3$$$-rd query, the height of each building is $$$3, 6, 5, 6, 10$$$.After the $$$4$$$-th query, the height of each building is $$$2, 7, 7, 7, 10$$$.After the $$$5$$$-th query, the height of each building is $$$2, 7, 7, 7, 10$$$.After the $$$6$$$-th query, the height of each building is $$$2, 9, 7, 7, 10$$$.


Pak Chanek is participating in a lemper cooking competition. In the competition, Pak Chanek has to cook lempers with $$$N$$$ stoves that are arranged sequentially from stove $$$1$$$ to stove $$$N$$$. Initially, stove $$$i$$$ has a temperature of $$$A_i$$$ degrees. A stove can have a negative temperature.Pak Chanek realises that, in order for his lempers to be cooked, he needs to keep the temperature of each stove at a non-negative value. To make it happen, Pak Chanek can do zero or more operations. In one operation, Pak Chanek chooses one stove $$$i$$$ with $$$2 \leq i \leq N-1$$$, then:  changes the temperature of stove $$$i-1$$$ into $$$A_{i-1} := A_{i-1} + A_{i}$$$,  changes the temperature of stove $$$i+1$$$ into $$$A_{i+1} := A_{i+1} + A_{i}$$$, and  changes the temperature of stove $$$i$$$ into $$$A_i := -A_i$$$. Pak Chanek wants to know the minimum number of operations he needs to do such that the temperatures of all stoves are at non-negative values. Help Pak Chanek by telling him the minimum number of operations needed or by reporting if it is not possible to do.

The first line contains a single integer $$$N$$$ ($$$1 \le N \le 10^5$$$) — the number of stoves. The second line contains $$$N$$$ integers $$$A_1, A_2, \ldots, A_N$$$ ($$$-10^9 \leq A_i \leq 10^9$$$) — the initial temperatures of the stoves.

Output an integer representing the minimum number of operations needed to make the temperatures of all stoves at non-negative values or output $$$-1$$$ if it is not possible.

NoteFor the first example, a sequence of operations that can be done is as follows:   Pak Chanek does an operation to stove $$$3$$$, $$$A = [2, -2, 1, 4, 2, -2, 9]$$$.  Pak Chanek does an operation to stove $$$2$$$, $$$A = [0, 2, -1, 4, 2, -2, 9]$$$.  Pak Chanek does an operation to stove $$$3$$$, $$$A = [0, 1, 1, 3, 2, -2, 9]$$$.  Pak Chanek does an operation to stove $$$6$$$, $$$A = [0, 1, 1, 3, 0, 2, 7]$$$. There is no other sequence of operations such that the number of operations needed is fewer than $$$4$$$.


Pak Chanek is playing one of his favourite board games. In the game, there is a directed graph with $$$N$$$ vertices and $$$M$$$ edges. In the graph, edge $$$i$$$ connects two different vertices $$$U_i$$$ and $$$V_i$$$ with a length of $$$W_i$$$. By using the $$$i$$$-th edge, something can move from $$$U_i$$$ to $$$V_i$$$, but not from $$$V_i$$$ to $$$U_i$$$.To play this game, initially Pak Chanek must place both of his hands onto two different vertices. In one move, he can move one of his hands to another vertex using an edge. To move a hand from vertex $$$U_i$$$ to vertex $$$V_i$$$, Pak Chanek needs a time of $$$W_i$$$ seconds. Note that Pak Chanek can only move one hand at a time. This game ends when both of Pak Chanek's hands are on the same vertex.Pak Chanek has several questions. For each $$$p$$$ satisfying $$$2 \leq p \leq N$$$, you need to find the minimum time in seconds needed for Pak Chanek to end the game if initially Pak Chanek's left hand and right hand are placed on vertex $$$1$$$ and vertex $$$p$$$, or report if it is impossible.

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$2 \leq N \leq 10^5$$$, $$$0 \leq M \leq 2 \cdot 10^5$$$) — the number of vertices and edges in the graph. The $$$i$$$-th of the next $$$M$$$ lines contains three integers $$$U_i$$$, $$$V_i$$$, and $$$W_i$$$ ($$$1 \le U_i, V_i \le N$$$, $$$U_i \neq V_i$$$, $$$1 \le W_i \le 10^9$$$) — a directed edge that connects two different vertices $$$U_i$$$ and $$$V_i$$$ with a length of $$$W_i$$$. There is no pair of different edges $$$i$$$ and $$$j$$$ such that $$$U_i = U_j$$$ and $$$V_i = V_j$$$.

Output a line containing $$$N-1$$$ integers. The $$$j$$$-th integer represents the minimum time in seconds needed by Pak Chanek to end the game if initially Pak Chanek's left hand and right hand are placed on vertex $$$1$$$ and vertex $$$j+1$$$, or $$$-1$$$ if it is impossible.

NoteIf initially Pak Chanek's left hand is on vertex $$$1$$$ and his right hand is on vertex $$$5$$$, Pak Chanek can do the following moves:   Move his right hand to vertex $$$4$$$ in $$$1$$$ second.  Move his left hand to vertex $$$2$$$ in $$$2$$$ seconds.  Move his left hand to vertex $$$4$$$ in $$$1$$$ second. In total it needs $$$1+2+1=4$$$ seconds. It can be proven that there is no other way that is faster.


Mainak has an array $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers. He will do the following operation to this array exactly once:  Pick a subsegment of this array and cyclically rotate it by any amount.  Formally, he can do the following exactly once:  Pick two integers $$$l$$$ and $$$r$$$, such that $$$1 \le l \le r \le n$$$, and any positive integer $$$k$$$.  Repeat this $$$k$$$ times: set $$$a_l=a_{l+1}, a_{l+1}=a_{l+2}, \ldots, a_{r-1}=a_r, a_r=a_l$$$ (all changes happen at the same time). Mainak wants to maximize the value of $$$(a_n - a_1)$$$ after exactly one such operation. Determine the maximum value of $$$(a_n - a_1)$$$ that he can obtain.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2000$$$). The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 999$$$). It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2000$$$.

For each test case, output a single integer — the maximum value of $$$(a_n - a_1)$$$ that Mainak can obtain by doing the operation exactly once.

Note In the first test case, we can rotate the subarray from index $$$3$$$ to index $$$6$$$ by an amount of $$$2$$$ (i.e. choose $$$l = 3$$$, $$$r = 6$$$ and $$$k = 2$$$) to get the optimal array: $$$$$$[1, 3, \underline{9, 11, 5, 7}] \longrightarrow [1, 3, \underline{5, 7, 9, 11}]$$$$$$ So the answer is $$$a_n - a_1 = 11 - 1 = 10$$$. In the second testcase, it is optimal to rotate the subarray starting and ending at index $$$1$$$ and rotating it by an amount of $$$2$$$. In the fourth testcase, it is optimal to rotate the subarray starting from index $$$1$$$ to index $$$4$$$ and rotating it by an amount of $$$3$$$. So the answer is $$$8 - 1 = 7$$$.


Last summer, Feluda gifted Lalmohan-Babu a balanced bracket sequence $$$s$$$ of length $$$2 n$$$.Topshe was bored during his summer vacations, and hence he decided to draw an undirected graph of $$$2 n$$$ vertices using the balanced bracket sequence $$$s$$$. For any two distinct vertices $$$i$$$ and $$$j$$$ ($$$1 \le i < j \le 2 n$$$), Topshe draws an edge (undirected and unweighted) between these two nodes if and only if the subsegment $$$s[i \ldots j]$$$ forms a balanced bracket sequence.Determine the number of connected components in Topshe's graph.See the Notes section for definitions of the underlined terms.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. 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 number of opening brackets in string $$$s$$$. The second line of each test case contains a string $$$s$$$ of length $$$2 n$$$ — a balanced bracket sequence consisting of $$$n$$$ opening brackets "(", and $$$n$$$ closing brackets ")". It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, output a single integer — the number of connected components in Topshe's graph.

NoteSample explanation:In the first test case, the graph constructed from the bracket sequence (), is just a graph containing nodes $$$1$$$ and $$$2$$$ connected by a single edge. In the second test case, the graph constructed from the bracket sequence ()(()) would be the following (containing two connected components):  Definition of Underlined Terms: A sequence of brackets is called balanced if one can turn it into a valid math expression by adding characters $$$+$$$ and $$$1$$$. For example, sequences (())(), (), and (()(())) are balanced, while )(, ((), and (()))( are not. The subsegment $$$s[l \ldots r]$$$ denotes the sequence $$$[s_l, s_{l + 1}, \ldots, s_r]$$$. A connected component is a set of vertices $$$X$$$ such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to $$$X$$$ violates this rule.


Mainak has two positive integers $$$n$$$ and $$$m$$$.Mainak finds a sequence $$$a_1, a_2, \ldots, a_n$$$ of $$$n$$$ positive integers interesting, if for all integers $$$i$$$ ($$$1 \le i \le n$$$), the bitwise XOR of all elements in $$$a$$$ which are strictly less than $$$a_i$$$ is $$$0$$$. Formally if $$$p_i$$$ is the bitwise XOR of all elements in $$$a$$$ which are strictly less than $$$a_i$$$, then $$$a$$$ is an interesting sequence if $$$p_1 = p_2 = \ldots = p_n = 0$$$.For example, sequences $$$[1,3,2,3,1,2,3]$$$, $$$[4,4,4,4]$$$, $$$[25]$$$ are interesting, whereas $$$[1,2,3,4]$$$ ($$$p_2 = 1 \ne 0$$$), $$$[4,1,1,2,4]$$$ ($$$p_1 = 1 \oplus 1 \oplus 2 = 2 \ne 0$$$), $$$[29,30,30]$$$ ($$$p_2 = 29 \ne 0$$$) aren't interesting.Here $$$a \oplus b$$$ denotes bitwise XOR of integers $$$a$$$ and $$$b$$$.Find any interesting sequence $$$a_1, a_2, \ldots, a_n$$$ (or report that there exists no such sequence) such that the sum of the elements in the sequence $$$a$$$ is equal to $$$m$$$, i.e. $$$a_1 + a_2 \ldots + a_n = m$$$.As a reminder, the bitwise XOR of an empty sequence is considered to be $$$0$$$.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. Description of the test cases follows. The first line and the only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n \le 10^5$$$, $$$1 \le m \le 10^9$$$) — the length of the sequence and the sum of the elements. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, if there exists some interesting sequence, output "Yes" on the first line, otherwise output "No". You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer). If the answer is "Yes", output $$$n$$$ positive integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i \ge 1$$$), forming an interesting sequence such that $$$a_1 + a_2 \ldots + a_n = m$$$. If there are multiple solutions, output any.

Note In the first test case, $$$[3]$$$ is the only interesting sequence of length $$$1$$$ having sum $$$3$$$. In the third test case, there is no sequence of length $$$2$$$ having sum of elements equal to $$$1$$$, so there is no such interesting sequence. In the fourth test case, $$$p_1 = p_2 = p_3 = 0$$$, because bitwise XOR of an empty sequence is $$$0$$$.


A permutation $$$p$$$ of length $$$n$$$ is called almost perfect if for all integer $$$1 \leq i \leq n$$$, it holds that $$$\lvert p_i - p^{-1}_i \rvert \le 1$$$, where $$$p^{-1}$$$ is the inverse permutation of $$$p$$$ (i.e. $$$p^{-1}_{k_1} = k_2$$$ if and only if $$$p_{k_2} = k_1$$$).Count the number of almost perfect permutations of length $$$n$$$ modulo $$$998244353$$$.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The description of each test case follows. The first and only line of each test case contains a single integer $$$n$$$ ($$$1 \leq n \leq 3 \cdot 10^5$$$) — the length of the permutation. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

For each test case, output a single integer — the number of almost perfect permutations of length $$$n$$$ modulo $$$998244353$$$.

NoteFor $$$n = 2$$$, both permutations $$$[1, 2]$$$, and $$$[2, 1]$$$ are almost perfect.For $$$n = 3$$$, there are only $$$6$$$ permutations. Having a look at all of them gives us:  $$$[1, 2, 3]$$$ is an almost perfect permutation.  $$$[1, 3, 2]$$$ is an almost perfect permutation.  $$$[2, 1, 3]$$$ is an almost perfect permutation.  $$$[2, 3, 1]$$$ is NOT an almost perfect permutation ($$$\lvert p_2 - p^{-1}_2 \rvert = \lvert 3 - 1 \rvert = 2$$$).  $$$[3, 1, 2]$$$ is NOT an almost perfect permutation ($$$\lvert p_2 - p^{-1}_2 \rvert = \lvert 1 - 3 \rvert = 2$$$).  $$$[3, 2, 1]$$$ is an almost perfect permutation. So we get $$$4$$$ almost perfect permutations.


You are given a connected, undirected and unweighted graph with $$$n$$$ vertices and $$$m$$$ edges. Notice the limit on the number of edges: $$$m \le n + 2$$$.Let's say we color some of the edges red and the remaining edges blue. Now consider only the red edges and count the number of connected components in the graph. Let this value be $$$c_1$$$. Similarly, consider only the blue edges and count the number of connected components in the graph. Let this value be $$$c_2$$$.Find an assignment of colors to the edges such that the quantity $$$c_1+c_2$$$ is minimised.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. 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$$$; $$$n-1 \leq m \leq \min{\left(n+2,\frac{n \cdot (n-1)}{2}\right)}$$$) — the number of vertices and the number of edges respectively. $$$m$$$ lines follow. The $$$i$$$-th line contains two integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \le u_i,v_i \le n$$$, $$$u_i \ne v_i$$$) denoting that the $$$i$$$-th edge goes between vertices $$$u_i$$$ and $$$v_i$$$. The input is guaranteed to have no multiple edges or self loops. The graph is also guaranteed to be connected. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^6$$$. It is guaranteed that the sum of $$$m$$$ over all test cases does not exceed $$$2 \cdot 10^6$$$.

For each test case, output a binary string of length $$$m$$$. The $$$i$$$-th character of the string should be 1 if the $$$i$$$-th edge should be colored red, and 0 if it should be colored blue. If there are multiple ways to assign colors to edges that give the minimum answer, you may output any.

Note The corresponding graph of the first test case is:  $$$c_1 + c_2 = 1 + 2 = 3$$$ The corresponding graph of the second test case is:  $$$c_1 + c_2 = 2 + 2 = 4$$$


There are $$$n$$$ people at a party. The $$$i$$$-th person has an amount of happiness $$$a_i$$$.Every person has a certain kind of personality which can be represented as a binary integer $$$b$$$. If $$$b = 0$$$, it means the happiness of the person will increase if he tells the story to someone strictly less happy than them. If $$$b = 1$$$, it means the happiness of the person will increase if he tells the story to someone strictly more happy than them.Let us define a speaking order as an ordering of the people from left to right. Now the following process occurs. We go from left to right. The current person tells the story to all people other than himself. Note that all happiness values stay constant while this happens. After the person is done, he counts the number of people who currently have strictly less/more happiness than him as per his kind of personality, and his happiness increases by that value. Note that only the current person's happiness value increases.As the organizer of the party, you don't want anyone to leave sad. Therefore, you want to count the number of speaking orders such that at the end of the process all $$$n$$$ people have equal happiness.Two speaking orders are considered different if there exists at least one person who does not have the same position in the two speaking orders.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of people. The second line contains a sequence of $$$n$$$ integers $$$a_1,a_2,...,a_n$$$ ($$$1 \leq a_i \leq 2n$$$)  — the happiness values. The third line contains a sequence of $$$n$$$ binary numbers $$$b_1,b_2,...,b_n$$$ ($$$b_i \in \{0,1\}$$$)  — the kinds of personality.

Output the number of different valid speaking orders. Since this number can be large, output it modulo $$$998244353$$$.

NoteHere is the explanation for the first example. One valid speaking order is $$$[2,1,4,3]$$$ (here, we have written the indices of each person). Each step shows the current happiness values and results.Step $$$1$$$: $$$[1,2,4,4]$$$ $$$\rightarrow$$$ Person $$$2$$$ tells the story to others. Since his kind of personality is $$$1$$$, his happiness increases by $$$2$$$ since persons $$$3$$$ and $$$4$$$ have strictly greater happiness.Step $$$2$$$: $$$[1,4,4,4]$$$ $$$\rightarrow$$$ Person $$$1$$$ tells the story to others. Since his kind of personality is $$$1$$$, his happiness increases by $$$3$$$ since persons $$$2$$$, $$$3$$$ and $$$4$$$ have strictly greater happiness.Step $$$3$$$: $$$[4,4,4,4]$$$ $$$\rightarrow$$$ Person $$$4$$$ tells the story to others. Since his kind of personality is $$$0$$$, his happiness increases by $$$0$$$ since no one has strictly lesser happiness.Step $$$4$$$: $$$[4,4,4,4]$$$ $$$\rightarrow$$$ Person $$$3$$$ tells the story to others. Since his kind of personality is $$$0$$$, his happiness increases by $$$0$$$ since no one has strictly lesser happiness.At the end, everyone has equal happiness.Note that $$$[2,1,3,4]$$$ is also a valid answer for this example.It can be shown that there is no valid ordering for the second example.


This problem was copied by the author from another online platform. Codeforces strongly condemns this action and therefore further submissions to this problem are not accepted.Debajyoti has a very important meeting to attend and he is already very late. Harsh, his driver, needs to take Debajyoti to the destination for the meeting as fast as possible.Harsh needs to pick up Debajyoti from his home and take him to the destination so that Debajyoti can attend the meeting in time. A straight road with $$$n$$$ traffic lights connects the home and the destination for the interview. The traffic lights are numbered in order from $$$1$$$ to $$$n$$$.Each traffic light cycles after $$$t$$$ seconds. The $$$i$$$-th traffic light is $$$\color{green}{\text{green}}$$$ (in which case Harsh can cross the traffic light) for the first $$$g_i$$$ seconds, and $$$\color{red}{\text{red}}$$$ (in which case Harsh must wait for the light to turn $$$\color{green}{\text{green}}$$$) for the remaining $$$(t−g_i)$$$ seconds, after which the pattern repeats. Each light's cycle repeats indefinitely and initially, the $$$i$$$-th light is $$$c_i$$$ seconds into its cycle (a light with $$$c_i=0$$$ has just turned $$$\color{green}{\text{green}}$$$). In the case that Harsh arrives at a light at the same time it changes colour, he will obey the new colour. Formally, the $$$i$$$-th traffic light is $$$\color{green}{\text{green}}$$$ from $$$[0,g_i)$$$ and $$$\color{red}{\text{red}}$$$ from $$$[g_i,t)$$$ (after which it repeats the cycle). The $$$i$$$-th traffic light is initially at the $$$c_i$$$-th second of its cycle.From the $$$i$$$-th traffic light, exactly $$$d_i$$$ seconds are required to travel to the next traffic light (that is to the $$$(i+1)$$$-th light). Debajyoti's home is located just before the first light and Debajyoti drops for the interview as soon as he passes the $$$n$$$-th light. In other words, no time is required to reach the first light from Debajyoti's home or to reach the interview centre from the $$$n$$$-th light.Harsh does not know how much longer it will take for Debajyoti to get ready. While waiting, he wonders what is the minimum possible amount of time he will spend driving provided he starts the moment Debajyoti arrives, which can be anywhere between $$$0$$$ to $$$\infty$$$ seconds from now. Can you tell Harsh the minimum possible amount of time he needs to spend on the road?Please note that Harsh can only start or stop driving at integer moments of time.

The first line of input will contain two integers, $$$n$$$ and $$$t$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$2 \le t \le 10^9$$$) denoting the number of traffic lights and the cycle length of the traffic lights respectively. $$$n$$$ lines of input follow. The $$$i$$$-th line will contain two integers $$$g_i$$$ and $$$c_i$$$ ($$$1 \le g_i < t$$$, $$$0 \le c_i < t$$$) describing the $$$i$$$-th traffic light. The following line of input contains $$$n−1$$$ integers $$$d_1, d_2, \ldots, d_{n-1}$$$ ($$$0 \le d_i \le 10^9$$$) — the time taken to travel from the $$$i$$$-th to the $$$(i+1)$$$-th traffic light.

Output a single integer — the minimum possible amount of time Harsh will spend driving.

NoteIn the first example, Harsh can do the following: Initially, the $$$5$$$ traffic lights are at the following seconds in their cycle: $$$\{2,3,6,2,0\}$$$. An optimal time for Harsh to start is if Debajyoti arrives after $$$1$$$ second. Note that this $$$1$$$ second will not be counted in the final answer. The lights will be now at $$$\{3,4,7,3,1\}$$$, so Harsh can drive from the $$$1$$$-st light to the $$$2$$$-nd light, which requires $$$1$$$ second to travel. The lights are now at $$$\{4,5,8,4,2\}$$$, so Harsh can continue driving, without stopping, to the $$$3$$$-rd light, which requires $$$2$$$ seconds to travel. The lights are now at $$$\{6,7,0,6,4\}$$$, so Harsh continues to the $$$4$$$-th light, which requires $$$3$$$ seconds to travel. The lights are now at $$$\{9,0,3,9,7\}$$$. Harsh must wait $$$1$$$ second for the $$$4$$$-th light to turn green before going to the $$$5$$$-th light, which requires $$$4$$$ seconds to travel. The lights are now at $$$\{4,5,8,4,2\}$$$, so Harsh can continue traveling, without stopping, to the meeting destination. The total time that Harsh had to drive for is $$$1+2+3+1+4=11$$$ seconds.In the second example, Harsh can do the following: Initially, the $$$6$$$ traffic lights are at the following seconds in their cycle: $$$\{3,5,0,8,7,6\}$$$. An optimal time for Harsh to start is if Debajyoti arrives after $$$1$$$ second. Note that this $$$1$$$ second will not be counted in the final answer. The lights will be now at $$$\{4,6,1,0,8,7\}$$$, so Harsh can drive from the $$$1$$$-st light to the $$$2$$$-nd light, which requires $$$0$$$ seconds to travel. The lights are still at $$$\{4,6,1,0,8,7\}$$$. Harsh must wait $$$3$$$ seconds for the $$$2$$$-nd light to turn green, before going to the $$$3$$$-rd light, which requires $$$0$$$ seconds to travel. The lights are now at $$$\{7,0,4,3,2,1\}$$$, so Harsh continues to the $$$4$$$-th light, which requires $$$0$$$ seconds to travel. The lights are still at $$$\{7,0,4,3,2,1\}$$$, so Harsh continues to the $$$5$$$-th light, which requires $$$0$$$ seconds to travel. The lights are still at $$$\{7,0,4,3,2,1\}$$$, so Harsh continues to the $$$6$$$-th light, which requires $$$0$$$ seconds to travel. The lights are still at $$$\{7,0,4,3,2,1\}$$$, so Harsh can continue traveling, without stopping, to the meeting destination. The total time that Harsh had to drive for is $$$0+3+0+0+0=3$$$ seconds.


The title is a reference to the very first Educational Round from our writers team, Educational Round 18.There is a bag, containing colored balls. There are $$$n$$$ different colors of balls, numbered from $$$1$$$ to $$$n$$$. There are $$$\mathit{cnt}_i$$$ balls of color $$$i$$$ in the bag. The total amount of balls in the bag is odd (e. g. $$$\mathit{cnt}_1 + \mathit{cnt}_2 + \dots + \mathit{cnt}_n$$$ is odd).In one move, you can choose two balls with different colors and take them out of the bag.At some point, all the remaining balls in the bag will have the same color. That's when you can't make moves anymore.Find any possible color of the remaining balls.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. The first line of each testcase contains a single integer $$$n$$$ ($$$1 \le n \le 20$$$) — the number of colors. The second line contains $$$n$$$ integers $$$\mathit{cnt}_1, \mathit{cnt}_2, \dots, \mathit{cnt}_n$$$ ($$$1 \le \mathit{cnt}_i \le 100$$$) — the amount of balls of each color in the bag. The total amount of balls in the bag is odd (e. g. $$$\mathit{cnt}_1 + \mathit{cnt}_2 + \dots + \mathit{cnt}_n$$$ is odd).

For each testcase, print a single integer — any possible color of the remaining balls, after you made some moves and can't make moves anymore.

NoteIn the first testcase, your first and only move can be one of the following:   take balls with colors $$$1$$$ and $$$2$$$;  take balls with colors $$$1$$$ and $$$3$$$;  take balls with colors $$$2$$$ and $$$3$$$. After the move, exactly one ball will remain. Its color can be $$$3, 2$$$ or $$$1$$$ depending on the move.In the second testcase, you can't make moves at all — there is only color of balls already. This color is $$$1$$$.In the third testcase, you can keep removing one ball of color $$$1$$$ and one ball of color $$$2$$$ until there are no more balls of color $$$1$$$. At the end, three balls of color $$$2$$$ remain.


Let's define the value of the permutation $$$p$$$ of $$$n$$$ integers $$$1$$$, $$$2$$$, ..., $$$n$$$ (a permutation is an array where each element from $$$1$$$ to $$$n$$$ occurs exactly once) as follows:  initially, an integer variable $$$x$$$ is equal to $$$0$$$;  if $$$x < p_1$$$, then add $$$p_1$$$ to $$$x$$$ (set $$$x = x + p_1$$$), otherwise assign $$$0$$$ to $$$x$$$;  if $$$x < p_2$$$, then add $$$p_2$$$ to $$$x$$$ (set $$$x = x + p_2$$$), otherwise assign $$$0$$$ to $$$x$$$;  ...  if $$$x < p_n$$$, then add $$$p_n$$$ to $$$x$$$ (set $$$x = x + p_n$$$), otherwise assign $$$0$$$ to $$$x$$$;  the value of the permutation is $$$x$$$ at the end of this process. For example, for $$$p = [4, 5, 1, 2, 3, 6]$$$, the value of $$$x$$$ changes as follows: $$$0, 4, 9, 0, 2, 5, 11$$$, so the value of the permutation is $$$11$$$.You are given an integer $$$n$$$. Find a permutation $$$p$$$ of size $$$n$$$ with the maximum possible value among all permutations of size $$$n$$$. If there are several such permutations, you can print any of them.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 97$$$) — the number of test cases. The only line of each test case contains one integer $$$n$$$ ($$$4 \le n \le 100$$$).

For each test case, print $$$n$$$ integers — the permutation $$$p$$$ of size $$$n$$$ with the maximum possible value among all permutations of size $$$n$$$.


Mainak has a convex polygon $$$\mathcal P$$$ with $$$n$$$ vertices labelled as $$$A_1, A_2, \ldots, A_n$$$ in a counter-clockwise fashion. The coordinates of the $$$i$$$-th point $$$A_i$$$ are given by $$$(x_i, y_i)$$$, where $$$x_i$$$ and $$$y_i$$$ are both integers.Further, it is known that the interior angle at $$$A_i$$$ is either a right angle or a proper obtuse angle. Formally it is known that:   $$$90 ^ \circ \le \angle A_{i - 1}A_{i}A_{i + 1} < 180 ^ \circ$$$, $$$\forall i \in \{1, 2, \ldots, n\}$$$ where we conventionally consider $$$A_0 = A_n$$$ and $$$A_{n + 1} = A_1$$$. Mainak's friend insisted that all points $$$Q$$$ such that there exists a chord of the polygon $$$\mathcal P$$$ passing through $$$Q$$$ with length not exceeding $$$1$$$, must be coloured $$$\color{red}{\text{red}}$$$. Mainak wants you to find the area of the coloured region formed by the $$$\color{red}{\text{red}}$$$ points.Formally, determine the area of the region $$$\mathcal S = \{Q \in \mathcal{P}$$$ | $$$Q \text{ is coloured } \color{red}{\text{red}}\}$$$.Recall that a chord of a polygon is a line segment between two points lying on the boundary (i.e. vertices or points on edges) of the polygon.

The first line contains an integer $$$n$$$ ($$$4 \le n \le 5000$$$) — the number of vertices of a polygon $$$\mathcal P$$$. The $$$i$$$-th line of the next $$$n$$$ lines contain two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i, y_i \le 10^9$$$) — the coordinates of $$$A_i$$$. Additional constraint on the input: The vertices form a convex polygon and are listed in counter-clockwise order. It is also guaranteed that all interior angles are in the range $$$[90^\circ ; 180^\circ )$$$.

Print the area of the region coloured in $$$\color{red}{\text{red}}$$$. Your answer is considered correct if its absolute or relative error does not exceed $$$10^{-4}$$$. Formally, let your answer be $$$a$$$, and the jury's answer be $$$b$$$. Your answer is accepted if and only if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-4}$$$.

NoteIn the first example, the polygon $$$\mathcal P$$$ can be visualised on the Cartesian Plane as:


Let's define $$$f(x)$$$ for a positive integer $$$x$$$ as the length of the base-10 representation of $$$x$$$ without leading zeros. I like to call it a digital logarithm. Similar to a digital root, if you are familiar with that.You are given two arrays $$$a$$$ and $$$b$$$, each containing $$$n$$$ positive integers. In one operation, you do the following:   pick some integer $$$i$$$ from $$$1$$$ to $$$n$$$;  assign either $$$f(a_i)$$$ to $$$a_i$$$ or $$$f(b_i)$$$ to $$$b_i$$$. Two arrays are considered similar to each other if you can rearrange the elements in both of them, so that they are equal (e. g. $$$a_i = b_i$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$).What's the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other?

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of elements in each of the arrays. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < 10^9$$$). The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_j < 10^9$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$2 \cdot 10^5$$$.

For each testcase, print the smallest number of operations required to make $$$a$$$ and $$$b$$$ similar to each other.

NoteIn the first testcase, you can apply the digital logarithm to $$$b_1$$$ twice.In the second testcase, the arrays are already similar to each other.In the third testcase, you can first apply the digital logarithm to $$$a_1$$$, then to $$$b_2$$$.


Yeri has an array of $$$n + 2$$$ non-negative integers : $$$a_0, a_1, ..., a_n, a_{n + 1}$$$.We know that $$$a_0 = a_{n + 1} = 0$$$.She wants to make all the elements of $$$a$$$ equal to zero in the minimum number of operations.In one operation she can do one of the following:  Choose the leftmost maximum element and change it to the maximum of the elements on its left. Choose the rightmost maximum element and change it to the maximum of the elements on its right.Help her find the minimum number of operations needed to make all elements of $$$a$$$ equal to zero.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \le a_i \le n$$$).

Print a single integer  — the minimum number of operations needed to make all elements of $$$a$$$ equal to zero.

NoteIn the first sample, you get $$$\langle 1, \underline{1}, 2, 4, 0, 2 \rangle$$$ by performing the first operation and $$$\langle 1, 4, 2, \underline{2}, 0, 2 \rangle$$$ by performing the second operation.One way to achieve our goal is shown below. (The underlines show the last change.) $$$\langle 1, 4, 2, 4, 0, 2 \rangle \to \langle 1, 4, 2, \underline{2}, 0, 2 \rangle \to \langle 1, \underline{1}, 2, 2, 0, 2 \rangle \to \langle 1, 1, 2, 2, 0, \underline{0} \rangle \to \langle 1, 1, 2, \underline{0}, 0, 0 \rangle \to \langle 1, 1, \underline{0}, 0, 0, 0 \rangle \to \langle \underline{0}, 1, 0, 0, 0, 0 \rangle \to \langle 0, \underline{0}, 0, 0, 0, 0 \rangle $$$In the third sample each element is already equal to zero so no operations are needed.


You are given a binary string $$$S$$$ of length $$$n$$$ indexed from $$$1$$$ to $$$n$$$. You can perform the following operation any number of times (possibly zero):Choose two integers $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$). Let $$$cnt_0$$$ be the number of times 0 occurs in $$$S[l \ldots r]$$$ and $$$cnt_1$$$ be the number of times 1 occurs in $$$S[l \ldots r]$$$. You can pay $$$|cnt_0 - cnt_1| + 1$$$ coins and sort the $$$S[l \ldots r]$$$. (by $$$S[l \ldots r]$$$ we mean the substring of $$$S$$$ starting at position $$$l$$$ and ending at position $$$r$$$)For example if $$$S = $$$ 11001, we can perform the operation on $$$S[2 \ldots 4]$$$, paying $$$|2 - 1| + 1 = 2$$$ coins, and obtain $$$S = $$$ 10011 as a new string.Find the minimum total number of coins required to sort $$$S$$$ in increasing order.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of $$$S$$$. The second line of each test case contains a binary string $$$S$$$ of $$$n$$$ characters $$$S_1S_2 \ldots S_n$$$. ($$$S_i = $$$ 0 or $$$S_i = $$$ 1 for each $$$1 \le i \le n$$$) It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, output the minimum total number of coins required to sort $$$S$$$ in increasing order.

NoteIn the first test case, $$$S$$$ is already sorted.In the second test case, it's enough to apply the operation with $$$l = 1, r = 2$$$.In the third test case, it's enough to apply the operation with $$$l = 1, r = 2$$$.


Define the score of some binary string $$$T$$$ as the absolute difference between the number of zeroes and ones in it. (for example, $$$T=$$$ 010001 contains $$$4$$$ zeroes and $$$2$$$ ones, so the score of $$$T$$$ is $$$|4-2| = 2$$$).Define the creepiness of some binary string $$$S$$$ as the maximum score among all of its prefixes (for example, the creepiness of $$$S=$$$ 01001 is equal to $$$2$$$ because the score of the prefix $$$S[1 \ldots 4]$$$ is $$$2$$$ and the rest of the prefixes have a score of $$$2$$$ or less).Given two integers $$$a$$$ and $$$b$$$, construct a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness.

The first line contains a single integer $$$t$$$ $$$(1\le t\le 1000)$$$  — the number of test cases. The description of the test cases follows. The only line of each test case contains two integers $$$a$$$ and $$$b$$$ ($$$ 1 \le a, b \le 100$$$)  — the numbers of zeroes and ones correspondingly.

For each test case, print a binary string consisting of $$$a$$$ zeroes and $$$b$$$ ones with the minimum possible creepiness. If there are multiple answers, print any of them.

NoteIn the first test case, the score of $$$S[1 \ldots 1]$$$ is $$$1$$$, and the score of $$$S[1 \ldots 2]$$$ is $$$0$$$.In the second test case, the minimum possible creepiness is $$$1$$$ and one of the other answers is 101.In the third test case, the minimum possible creepiness is $$$3$$$ and one of the other answers is 0001100.


Let's call a binary string $$$T$$$ of length $$$m$$$ indexed from $$$1$$$ to $$$m$$$ paranoid if we can obtain a string of length $$$1$$$ by performing the following two kinds of operations $$$m-1$$$ times in any order : Select any substring of $$$T$$$ that is equal to 01, and then replace it with 1. Select any substring of $$$T$$$ that is equal to 10, and then replace it with 0.For example, if $$$T = $$$ 001, we can select the substring $$$[T_2T_3]$$$ and perform the first operation. So we obtain $$$T = $$$ 01.You are given a binary string $$$S$$$ of length $$$n$$$ indexed from $$$1$$$ to $$$n$$$. Find the number of pairs of integers $$$(l, r)$$$ $$$1 \le l \le r \le n$$$ such that $$$S[l \ldots r]$$$ (the substring of $$$S$$$ from $$$l$$$ to $$$r$$$) is a paranoid string.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The description of test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of $$$S$$$. The second line of each test case contains a binary string $$$S$$$ of $$$n$$$ characters $$$S_1S_2 \ldots S_n$$$. ($$$S_i = $$$ 0 or $$$S_i = $$$ 1 for each $$$1 \le i \le n$$$) It is guaranteed that the sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case, output the number of pairs of integers $$$(l, r)$$$ $$$1 \le l \le r \le n$$$ such that $$$S[l \ldots r]$$$ (the substring of $$$S$$$ from $$$l$$$ to $$$r$$$) is a paranoid string.

NoteIn the first sample, $$$S$$$ already has length $$$1$$$ and doesn't need any operations.In the second sample, all substrings of $$$S$$$ are paranoid. For the entire string, it's enough to perform the first operation.In the third sample, all substrings of $$$S$$$ are paranoid except $$$[S_2S_3]$$$, because we can't perform any operations on it, and $$$[S_1S_2S_3]$$$ (the entire string).


Michael and Joe are playing a game. The game is played on a grid with $$$n$$$ rows and $$$m$$$ columns, filled with distinct integers. We denote the square on the $$$i$$$-th ($$$1\le i\le n$$$) row and $$$j$$$-th ($$$1\le j\le m$$$) column by $$$(i, j)$$$ and the number there by $$$a_{ij}$$$.Michael starts by saying two numbers $$$h$$$ ($$$1\le h \le n$$$) and $$$w$$$ ($$$1\le w \le m$$$). Then Joe picks any $$$h\times w$$$ subrectangle of the board (without Michael seeing).Formally, an $$$h\times w$$$ subrectangle starts at some square $$$(a,b)$$$ where $$$1 \le a \le n-h+1$$$ and $$$1 \le b \le m-w+1$$$. It contains all squares $$$(i,j)$$$ for $$$a \le i \le a+h-1$$$ and $$$b \le j \le b+w-1$$$.    Possible move by Joe if Michael says $$$3\times 2$$$ (with maximum of $$$15$$$). Finally, Michael has to guess the maximum number in the subrectangle. He wins if he gets it right.Because Michael doesn't like big numbers, he wants the area of the chosen subrectangle (that is, $$$h \cdot w$$$), to be as small as possible, while still ensuring that he wins, not depending on Joe's choice. Help Michael out by finding this minimum possible area. It can be shown that Michael can always choose $$$h, w$$$ for which he can ensure that he wins.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 20$$$). Description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 40$$$)  — the size of the grid. Each of the following $$$n$$$ lines contains $$$m$$$ integers. The $$$j$$$-th integer on the $$$i$$$-th line is $$$a_{ij}$$$ ($$$-10^9 \le a_{ij} \le 10^9$$$)  — the element in the cell $$$(i, j)$$$. It is guaranteed that all the numbers are distinct (that is, if $$$a_{i_1j_1} = a_{i_2j_2}$$$, then $$$i_1 = i_2, j_1 = j_2$$$).

For each test case print a single positive integer  — the minimum possible area the subrectangle can have while still ensuring that Michael can guarantee the victory.

NoteIn the first test case, the grid is $$$1\times 1$$$, so the only possible choice for $$$h, w$$$ is $$$h = 1, w = 1$$$, giving an area of $$$h\cdot w = 1$$$.The grid from the second test case is drawn in the statement. It can be shown that with $$$h = 3, w = 3$$$ Michael can guarantee the victory and that any choice with $$$h\cdot w \le 8$$$ doesn't.