On the board, Bob wrote $$$n$$$ positive integers in base $$$10$$$ with sum $$$s$$$ (i. e. in decimal numeral system). Alice sees the board, but accidentally interprets the numbers on the board as base-$$$11$$$ integers and adds them up (in base $$$11$$$).What numbers should Bob write on the board, so Alice's sum is as large as possible?

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 only line of each test case contains two integers $$$s$$$ and $$$n$$$ ($$$1 \leq s \leq 10^9$$$; $$$1 \leq n \leq \min(100, s)$$$) — the sum and amount of numbers on the board, respectively. Numbers $$$s$$$ and $$$n$$$ are given in decimal notation (base $$$10$$$).

For each test case, output $$$n$$$ positive integers — the numbers Bob should write on the board, so Alice's sum is as large as possible. If there are multiple answers, print any of them.

NoteIn the first test case, $$$70_{10} + 27_{10} = 97_{10}$$$, and Alice's sum is $$$$$$70_{11} + 27_{11} = 97_{11} = 9 \cdot 11 + 7 = 106_{10}.$$$$$$ (Here $$$x_b$$$ represents the number $$$x$$$ in base $$$b$$$.) It can be shown that it is impossible for Alice to get a larger sum than $$$106_{10}$$$.In the second test case, Bob can only write a single number on the board, so he must write $$$17$$$.In the third test case, $$$3_{10} + 4_{10} + 100_{10} + 4_{10} = 111_{10}$$$, and Alice's sum is $$$$$$3_{11} + 4_{11} + 100_{11} + 4_{11} = 110_{11} = 1 \cdot 11^2 + 1 \cdot 11 = 132_{10}.$$$$$$ It can be shown that it is impossible for Alice to get a larger sum than $$$132_{10}$$$.


Alice has recently received an array $$$a_1, a_2, \dots, a_n$$$ for her birthday! She is very proud of her array, and when she showed her friend Bob the array, he was very happy with her present too!However, soon Bob became curious, and as any sane friend would do, asked Alice to perform $$$q$$$ operations of two types on her array:  $$$1$$$ $$$x$$$ $$$y$$$: update the element $$$a_x$$$ to $$$y$$$ (set $$$a_x = y$$$).  $$$2$$$ $$$l$$$ $$$r$$$: calculate how many non-decreasing subarrays exist within the subarray $$$[a_l, a_{l+1}, \dots, a_r]$$$. More formally, count the number of pairs of integers $$$(p,q)$$$ such that $$$l \le p \le q \le r$$$ and $$$a_p \le a_{p+1} \le \dots \le a_{q-1} \le a_q$$$. Help Alice answer Bob's queries!

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2 \cdot 10^5$$$) — the size of the array, and the number of queries, respectively. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of Alice's array. The next $$$q$$$ lines consist of three integers each. The first integer of the $$$i$$$-th line is $$$t_i$$$, the operation being performed on the $$$i$$$-th step ($$$t_i = 1$$$ or $$$t_i = 2$$$). If $$$t_i = 1$$$, the next two integers are $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i \le n$$$; $$$1 \le y_i \le 10^9$$$), updating the element at position $$$x_i$$$ to $$$y_i$$$ (setting $$$a_{x_i} = y_i$$$). If $$$t_i = 2$$$, the next two integers are $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$), the two indices Bob asks Alice about for the $$$i$$$-th query. It's guaranteed that there is at least one operation of the second type.

For each query of type $$$2$$$, print a single integer, the answer to the query.


Alice has an empty grid with $$$n$$$ rows and $$$m$$$ columns. Some of the cells are marked, and no marked cells are adjacent to the edge of the grid. (Two squares are adjacent if they share a side.) Alice wants to fill each cell with a number such that the following statements are true:   every unmarked cell contains either the number $$$1$$$ or $$$4$$$;  every marked cell contains the sum of the numbers in all unmarked cells adjacent to it (if a marked cell is not adjacent to any unmarked cell, this sum is $$$0$$$);  every marked cell contains a multiple of $$$5$$$.  Alice couldn't figure it out, so she asks Bob to help her. Help Bob find any such grid, or state that no such grid exists.

The first line of input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n, m \leq 500$$$) — the number of rows and the number of columns in the grid, respectively. Then $$$n$$$ lines follow, each containing $$$m$$$ characters. Each of these characters is either '.' or 'X' — an unmarked and a marked cell, respectively. No marked cells are adjacent to the edge of the grid.

Output "'NO" if no suitable grid exists. Otherwise, output "'YES"'. Then output $$$n$$$ lines of $$$m$$$ space-separated integers — the integers in the grid.

NoteIt can be shown that no such grid exists for the second test.


You are given a string $$$s$$$, consisting of $$$n$$$ letters, each letter is either 'a' or 'b'. The letters in the string are numbered from $$$1$$$ to $$$n$$$.$$$s[l; r]$$$ is a continuous substring of letters from index $$$l$$$ to $$$r$$$ of the string inclusive. A string is called balanced if the number of letters 'a' in it is equal to the number of letters 'b'. For example, strings "baba" and "aabbab" are balanced and strings "aaab" and "b" are not.Find any non-empty balanced substring $$$s[l; r]$$$ of string $$$s$$$. Print its $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le n$$$). If there is no such substring, then print $$$-1$$$ $$$-1$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the length of the string. The second line of the testcase contains a string $$$s$$$, consisting of $$$n$$$ letters, each letter is either 'a' or 'b'.

For each testcase print two integers. If there exists a non-empty balanced substring $$$s[l; r]$$$, then print $$$l$$$ $$$r$$$ ($$$1 \le l \le r \le n$$$). Otherwise, print $$$-1$$$ $$$-1$$$.

NoteIn the first testcase there are no non-empty balanced subtrings.In the second and third testcases there are multiple balanced substrings, including the entire string "abbaba" and substring "baba".


A chess tournament will be held soon, where $$$n$$$ chess players will take part. Every participant will play one game against every other participant. Each game ends in either a win for one player and a loss for another player, or a draw for both players.Each of the players has their own expectations about the tournament, they can be one of two types:  a player wants not to lose any game (i. e. finish the tournament with zero losses);  a player wants to win at least one game. You have to determine if there exists an outcome for all the matches such that all the players meet their expectations. If there are several possible outcomes, print any of them. If there are none, report that it's impossible.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 200$$$) — the number of test cases. The first line of each test case contains one integer $$$n$$$ ($$$2 \le n \le 50$$$) — the number of chess players. The second line contains the string $$$s$$$ ($$$|s| = n$$$; $$$s_i \in \{1, 2\}$$$). If $$$s_i = 1$$$, then the $$$i$$$-th player has expectations of the first type, otherwise of the second type.

For each test case, print the answer in the following format: In the first line, print NO if it is impossible to meet the expectations of all players. Otherwise, print YES, and the matrix of size $$$n \times n$$$ in the next $$$n$$$ lines. The matrix element in the $$$i$$$-th row and $$$j$$$-th column should be equal to:   +, if the $$$i$$$-th player won in a game against the $$$j$$$-th player;  -, if the $$$i$$$-th player lost in a game against the $$$j$$$-th player;  =, if the $$$i$$$-th and $$$j$$$-th players' game resulted in a draw;  X, if $$$i = j$$$.


$$$n$$$ people gathered to hold a jury meeting of the upcoming competition, the $$$i$$$-th member of the jury came up with $$$a_i$$$ tasks, which they want to share with each other.First, the jury decides on the order which they will follow while describing the tasks. Let that be a permutation $$$p$$$ of numbers from $$$1$$$ to $$$n$$$ (an array of size $$$n$$$ where each integer from $$$1$$$ to $$$n$$$ occurs exactly once).Then the discussion goes as follows:  If a jury member $$$p_1$$$ has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped.  If a jury member $$$p_2$$$ has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped.  ...  If a jury member $$$p_n$$$ has some tasks left to tell, then they tell one task to others. Otherwise, they are skipped.  If there are still members with tasks left, then the process repeats from the start. Otherwise, the discussion ends. A permutation $$$p$$$ is nice if none of the jury members tell two or more of their own tasks in a row. Count the number of nice permutations. The answer may be really large, so print it modulo $$$998\,244\,353$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The first line of the test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — number of jury members. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — the number of problems that the $$$i$$$-th member of the jury came up with. The sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer — the number of nice permutations, taken modulo $$$998\,244\,353$$$.

NoteExplanation of the first test case from the example:There are two possible permutations, $$$p = [1, 2]$$$ and $$$p = [2, 1]$$$. For $$$p = [1, 2]$$$, the process is the following:  the first jury member tells a task;  the second jury member tells a task;  the first jury member doesn't have any tasks left to tell, so they are skipped;  the second jury member tells a task. So, the second jury member has told two tasks in a row (in succession), so the permutation is not nice.For $$$p = [2, 1]$$$, the process is the following:  the second jury member tells a task;  the first jury member tells a task;  the second jury member tells a task. So, this permutation is nice.


There is a city that can be represented as a square grid with corner points in $$$(0, 0)$$$ and $$$(10^6, 10^6)$$$.The city has $$$n$$$ vertical and $$$m$$$ horizontal streets that goes across the whole city, i. e. the $$$i$$$-th vertical streets goes from $$$(x_i, 0)$$$ to $$$(x_i, 10^6)$$$ and the $$$j$$$-th horizontal street goes from $$$(0, y_j)$$$ to $$$(10^6, y_j)$$$. All streets are bidirectional. Borders of the city are streets as well.There are $$$k$$$ persons staying on the streets: the $$$p$$$-th person at point $$$(x_p, y_p)$$$ (so either $$$x_p$$$ equal to some $$$x_i$$$ or $$$y_p$$$ equal to some $$$y_j$$$, or both).Let's say that a pair of persons form an inconvenient pair if the shortest path from one person to another going only by streets is strictly greater than the Manhattan distance between them.Calculate the number of inconvenient pairs of persons (pairs $$$(x, y)$$$ and $$$(y, x)$$$ are the same pair).Let's recall that Manhattan distance between points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$|x_1 - x_2| + |y_1 - y_2|$$$.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n, m \le 2 \cdot 10^5$$$; $$$2 \le k \le 3 \cdot 10^5$$$) — the number of vertical and horizontal streets and the number of persons. The second line of each test case contains $$$n$$$ integers $$$x_1, x_2, \dots, x_n$$$ ($$$0 = x_1 < x_2 < \dots < x_{n - 1} < x_n = 10^6$$$) — the $$$x$$$-coordinates of vertical streets. The third line contains $$$m$$$ integers $$$y_1, y_2, \dots, y_m$$$ ($$$0 = y_1 < y_2 < \dots < y_{m - 1} < y_m = 10^6$$$) — the $$$y$$$-coordinates of horizontal streets. Next $$$k$$$ lines contains description of people. The $$$p$$$-th line contains two integers $$$x_p$$$ and $$$y_p$$$ ($$$0 \le x_p, y_p \le 10^6$$$; $$$x_p \in \{x_1, \dots, x_n\}$$$ or $$$y_p \in \{y_1, \dots, y_m\}$$$) — the coordinates of the $$$p$$$-th person. All points are distinct. It guaranteed that sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$, sum of $$$m$$$ doesn't exceed $$$2 \cdot 10^5$$$ and sum of $$$k$$$ doesn't exceed $$$3 \cdot 10^5$$$.

For each test case, print the number of inconvenient pairs.

NoteThe second test case is pictured below:   For example, points $$$3$$$ and $$$4$$$ form an inconvenient pair, since the shortest path between them (shown red and equal to $$$7$$$) is greater than its Manhattan distance (equal to $$$5$$$).Points $$$3$$$ and $$$5$$$ also form an inconvenient pair: the shortest path equal to $$$1000001$$$ (shown green) is greater than the Manhattan distance equal to $$$999999$$$.But points $$$5$$$ and $$$9$$$ don't form an inconvenient pair, since the shortest path (shown purple) is equal to its Manhattan distance.


$$$2^k$$$ teams participate in a playoff tournament. The tournament consists of $$$2^k - 1$$$ games. They are held as follows: first of all, the teams are split into pairs: team $$$1$$$ plays against team $$$2$$$, team $$$3$$$ plays against team $$$4$$$ (exactly in this order), and so on (so, $$$2^{k-1}$$$ games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only $$$2^{k-1}$$$ teams remain. If only one team remains, it is declared the champion; otherwise, $$$2^{k-2}$$$ games are played: in the first one of them, the winner of the game "$$$1$$$ vs $$$2$$$" plays against the winner of the game "$$$3$$$ vs $$$4$$$", then the winner of the game "$$$5$$$ vs $$$6$$$" plays against the winner of the game "$$$7$$$ vs $$$8$$$", and so on. This process repeats until only one team remains.After the tournament ends, the teams are assigned places according to the tournament phase when they were eliminated. In particular:  the winner of the tournament gets place $$$1$$$;  the team eliminated in the finals gets place $$$2$$$;  both teams eliminated in the semifinals get place $$$3$$$;  all teams eliminated in the quarterfinals get place $$$5$$$;  all teams eliminated in the 1/8 finals get place $$$9$$$, and so on. For example, this picture describes one of the possible ways the tournament can go with $$$k = 3$$$, and the resulting places of the teams:  After a tournament which was conducted by the aforementioned rules ended, its results were encoded in the following way. Let $$$p_i$$$ be the place of the $$$i$$$-th team in the tournament. The hash value of the tournament $$$h$$$ is calculated as $$$h = (\sum \limits_{i=1}^{2^k} i \cdot A^{p_i}) \bmod 998244353$$$, where $$$A$$$ is some given integer.Unfortunately, due to a system crash, almost all tournament-related data was lost. The only pieces of data that remain are the values of $$$k$$$, $$$A$$$ and $$$h$$$. You are asked to restore the resulting placing of the teams in the tournament, if it is possible at all.

If it is impossible to find any placing of the teams that is consistent with the data you have, print one integer $$$-1$$$. Otherwise, print $$$2^k$$$ integers, where $$$i$$$-th integer should be equal to $$$p_i$$$ (the place of the $$$i$$$-th team). Note that your answer should be consistent with one of the possible ways the tournament could go, and note that the initial structure of the tournament is fixed (for example, teams $$$1$$$ and $$$2$$$ always play in the first phase of the tournament against each other). If there are multiple ways to restore the places of the teams which are consistent with the data you have, print any of them.

NoteThe tournament for the first example is described in the statement.For the third example, the placing $$$[1, 2, 3, 3]$$$ (team $$$1$$$ gets place $$$1$$$, team $$$2$$$ gets place $$$2$$$, teams $$$3$$$ and $$$4$$$ get place $$$3$$$) could result in a hash value of $$$7020100$$$ with $$$A = 100$$$, but no tournament can result in such placing since teams $$$1$$$ and $$$2$$$ play against each other in the semifinals, so they cannot get two first places.


You are given a simple undirected graph with $$$n$$$ vertices, $$$n$$$ is even. You are going to write a letter on each vertex. Each letter should be one of the first $$$k$$$ letters of the Latin alphabet.A path in the graph is called Hamiltonian if it visits each vertex exactly once. A string is called palindromic if it reads the same from left to right and from right to left. A path in the graph is called palindromic if the letters on the vertices in it spell a palindromic string without changing the order.A string of length $$$n$$$ is good if:   each letter is one of the first $$$k$$$ lowercase Latin letters;  if you write the $$$i$$$-th letter of the string on the $$$i$$$-th vertex of the graph, there will exist a palindromic Hamiltonian path in the graph. Note that the path doesn't necesserily go through the vertices in order $$$1, 2, \dots, n$$$.Count the number of good strings.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n \le 12$$$; $$$n$$$ is even; $$$0 \le m \le \frac{n \cdot (n-1)}{2}$$$; $$$1 \le k \le 12$$$) — the number of vertices in the graph, the number of edges in the graph and the number of first letters of the Latin alphabet that can be used. Each of the next $$$m$$$ lines contains two integers $$$v$$$ and $$$u$$$ ($$$1 \le v, u \le n$$$; $$$v \neq u$$$) — the edges of the graph. The graph doesn't contain multiple edges and self-loops.

Print a single integer — number of good strings.


Alex has bought a new novel that was published in $$$n$$$ volumes. He has read these volumes one by one, and each volume has taken him several (maybe one) full days to read. So, on the first day, he was reading the first volume, and on each of the following days, he was reading either the same volume he had been reading on the previous day, or the next volume.Let $$$v_i$$$ be the number of the volume Alex was reading on the $$$i$$$-th day. Here are some examples:  one of the possible situations is $$$v_1 = 1$$$, $$$v_2 = 1$$$, $$$v_3 = 2$$$, $$$v_4 = 3$$$, $$$v_5 = 3$$$ — this situation means that Alex has spent two days ($$$1$$$-st and $$$2$$$-nd) on the first volume, one day ($$$3$$$-rd) on the second volume, and two days ($$$4$$$-th and $$$5$$$-th) on the third volume;  a situation $$$v_1 = 2$$$, $$$v_2 = 2$$$, $$$v_3 = 3$$$ is impossible, since Alex started with the first volume (so $$$v_1$$$ cannot be anything but $$$1$$$);  a situation $$$v_1 = 1$$$, $$$v_2 = 2$$$, $$$v_3 = 3$$$, $$$v_4 = 1$$$ is impossible, since Alex won't return to the first volume after reading the third one;  a situation $$$v_1 = 1$$$, $$$v_2 = 3$$$ is impossible, since Alex doesn't skip volumes. You know that Alex was reading the volume $$$v_a$$$ on the day $$$a$$$, and the volume $$$v_c$$$ on the day $$$c$$$. Now you want to guess which volume was he reading on the day $$$b$$$, which is between the days $$$a$$$ and $$$c$$$ (so $$$a < b < c$$$). There may be some ambiguity, so you want to make any valid guess (i. e. choose some volume number $$$v_b$$$ so it's possible that Alex was reading volume $$$v_a$$$ on day $$$a$$$, volume $$$v_b$$$ on day $$$b$$$, and volume $$$v_c$$$ on day $$$c$$$).

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 100$$$). Description of the test cases follows. The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of volumes the novel consists of. The second line of each test case contains two integers $$$a$$$ and $$$v_a$$$ ($$$1 \le a \le 98$$$; $$$1 \le v_a \le a$$$) denoting that Alex was reading volume $$$v_a$$$ at day $$$a$$$. The third line of each test case contains two integers $$$c$$$ and $$$v_c$$$ ($$$a + 2 \le c \le 100$$$; $$$v_a \le v_c \le c$$$) denoting that Alex was reading volume $$$v_c$$$ at day $$$c$$$. The fourth line of each test case contains one integer $$$b$$$ ($$$a < b < c$$$) — the day you are interested in. It's guaranteed that the input is not controversial, in other words, Alex could read volume $$$v_a$$$ at day $$$a$$$ and volume $$$v_c$$$ at day $$$c$$$.

For each test case, print the possible index of volume Alex could read at day $$$b$$$. If there are multiple answers, print any.

NoteIn the first test case, since Alex was reading volume $$$1$$$ both at day $$$1$$$ and at day $$$100$$$ then he was reading volume $$$1$$$ at any day between them.In the second test case, Alex could read any volume from $$$1$$$ to $$$4$$$ at day $$$16$$$. For example, he could read volume $$$1$$$ from day $$$1$$$ to day $$$15$$$, volume $$$2$$$ at days $$$16$$$ and $$$17$$$, volume $$$3$$$ at day $$$18$$$ and volume $$$4$$$ at days $$$19$$$ and $$$20$$$.In the third test case, there is only one possible situation: Alex read one volume per day, so at day $$$42$$$ he read volume $$$42$$$.


Let's say that two strings $$$s$$$ and $$$t$$$ rhyme if both strings have length at least $$$k$$$, and their last $$$k$$$ characters are equal. For example, if $$$k = 3$$$, the strings abcd and cebcd rhyme, the strings ab and ab don't rhyme, the strings aaaa and aaaaa rhyme, the strings abcd and abce don't rhyme.You have $$$n$$$ pairs of strings $$$(s_i, t_i)$$$, and for each pair of strings you know, should they rhyme or should not.Find all possible non-negative integer values for $$$k$$$ such that pairs that have to rhyme, rhyme and pairs that must not rhyme, don't rhyme.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 1000$$$). 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 string pairs. Next $$$n$$$ lines contains descriptions of pairs — one per line. The $$$i$$$-th line contains space-separated strings $$$s_i$$$ and $$$t_i$$$ and marker $$$r_i$$$. Strings are non-empty, consist of lowercase Latin letters and each have length at most $$$2 \cdot 10^5$$$. The marker $$$r_i$$$ equals to $$$1$$$ if strings have to rhyme, or $$$0$$$ if they must not rhyme. It's guaranteed that for each test case there is at least one pair with $$$r_i$$$ equal to $$$1$$$ and that the total length of all strings over all test cases doesn't exceed $$$4 \cdot 10^5$$$.

For each test case, firstly print integer $$$m$$$ — the number of possible non-negative integer values of $$$k$$$ such that pairs that have to rhyme, rhyme and pairs that must not rhyme, don't rhyme. Next, print all these values of $$$k$$$ (without repetitions). You can print them in any order.

NoteIn the first test case, if $$$k$$$ is at least $$$1$$$ then kotlin and heroes don't rhyme.In the second test case, for $$$k = 2$$$ join and kotlin rhyme, and episode and eight don't rhyme.

3
1
kotlin heroes 1
2
join kotlin 1
episode eight 0
4
abc abcdef 0
xyz zzz 1
aaa bba 0
c d 0


Once upon a time, Petya had an array of integers $$$a$$$ of length $$$n$$$. But over time, the array itself was lost, and only $$$n-1$$$ results of comparisons of neighboring array elements remained. In other words, for every $$$i$$$ from $$$1$$$ to $$$n-1$$$, Petya knows exactly one of these three facts:  $$$a_i < a_{i+1}$$$;  $$$a_i = a_{i+1}$$$;  $$$a_i > a_{i+1}$$$. Petya wonders if it is possible to uniquely determine the result of comparing $$$a_1$$$ and $$$a_n$$$.You have to help Petya determine the result of comparing $$$a_1$$$ and $$$a_n$$$ or report that the result cannot be determined unambiguously.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 500$$$) — the number of test cases. The only line of the test case contains the string $$$s$$$ ($$$1 \le |s| \le 100$$$), where $$$s_i$$$ is:   <, if $$$a_i < a_{i + 1}$$$;  >, if $$$a_i > a_{i + 1}$$$;  =, if $$$a_i = a_{i + 1}$$$.

For each test case, print a single string equal to:   <, if $$$a_1 < a_n$$$;  >, if $$$a_1 > a_n$$$;  =, if $$$a_1 = a_n$$$;  ?, if it is impossible to uniquely determine the result of the comparison.

NoteConsider the test cases of the example:  in the first test case, it's easy to see that $$$a_1 > a_4$$$ since $$$a_1 > a_2 > a_3 > a_4$$$;  in the second test case, both sequences $$$[1, 2, 0, 10, 10, 15]$$$ and $$$[10, 11, 1, 2, 2, 5]$$$ meet the constraints; in the first one, $$$a_1 < a_6$$$, and in the second one, $$$a_1 > a_6$$$, so it's impossible to compare $$$a_1$$$ and $$$a_6$$$;  in the third test case, we already know that $$$a_1 = a_2$$$;  in the fourth test case, it's easy to see that $$$a_3 = a_4 = a_5$$$, and $$$a_1 < a_2 < a_3$$$, so $$$a_1 < a_5$$$.


Kotlin Heroes competition is nearing completion. This time $$$n$$$ programmers took part in the competition. Now organizers are thinking how to entertain spectators as well. One of the possibilities is holding sweepstakes. So for now they decided to conduct a survey among spectators.In total, organizers asked $$$m$$$ viewers two questions:   Who will take the first place?  Who will take the last place? After receiving answers, organizers ranked all spectators based on the number of programmers they guessed right. Suppose, there are $$$c_2$$$ viewers who guessed right both first and last place, $$$c_1$$$ viewers who guessed either first or last place right and $$$c_0$$$ viewers who didn't guess at all. All $$$c_2$$$ viewers will get rank $$$1$$$, all viewers with one right answer will get rank $$$c_2 + 1$$$ and all remaining viewers — rank $$$c_2 + c_1 + 1$$$.You were one of the interviewed spectators. Also, as one of the organizers, you have access to survey results, but not to competition results. Calculate, what is the worst rank you can possibly get according to organizers' ranking system?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le 1000$$$; $$$1 \le m \le 2 \cdot 10^5$$$) — the number of programmers participating in the competition and the number of surveyed spectators. Next $$$m$$$ lines contain answers of spectators. The $$$i$$$-th line contains two integers $$$f_i$$$ and $$$l_i$$$ ($$$1 \le f_i, l_i \le n$$$; $$$f_i \ne l_i$$$) — the indices of programmers who will take the first and last places in opinion of the $$$i$$$-th viewer. For simplicity, you are the first among spectators, so your answers are $$$f_1$$$ and $$$l_1$$$.

Print the single integer — the worst rank among spectators you can possibly get according to organizers' ranking system (bigger rank — worse, of course).

NoteIn the first example, if the second programmer takes first place, while the first programmer takes last place, you'll have $$$0$$$ right answers while the other two spectators — $$$2$$$ right answers. That's why your rank (in the worst case) will be $$$c_2 + c_1 + 1$$$ $$$=$$$ $$$2 + 0 + 1 = 3$$$.In the second example, for example, if the third programmer takes the first place and the second programmer takes the last place, then you'll have $$$1$$$ right answer. The spectators $$$2$$$, $$$4$$$ and $$$5$$$ will have $$$2$$$ right answers, spectator $$$6$$$ — $$$1$$$ right answer and spectator $$$3$$$ — $$$0$$$ right answers. As a result, your rank will be equal to $$$c_2 + 1$$$ $$$=$$$ $$$3 + 1 = 4$$$. (Note that spectator $$$6$$$ will have the same rank $$$4$$$).


Kotlinforces is a web platfrom that hosts programming competitions.The staff of Kotlinforces is asked to schedule $$$n$$$ programming competitions on the next $$$m$$$ days. Each competition is held in multiple stages; the regulations of the $$$i$$$-th competition state that this competition should consist of exactly $$$k_i$$$ stages, and each stage, starting from the second one, should be scheduled exactly $$$t_i$$$ days after the previous stage. In other words, if the first stage of the $$$i$$$-th competition is scheduled on day $$$x$$$, the second stage should be scheduled on day $$$x+t_i$$$, the third stage — on day $$$x+2t_i$$$, ..., the $$$k_i$$$-th stage (which is the last one) — on day $$$x+(k_i-1)t_i$$$.All $$$n$$$ competitions should be scheduled in such a way that they start and finish during the next $$$m$$$ days, and on any of these $$$m$$$ days, at most one stage of one competition is held (two stages of different competitions should not be scheduled on the same day).Is it possible to schedule all $$$n$$$ competitions to meet these constraints?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 5000$$$) — the number of competitions and the number of days, respectively. Then $$$n$$$ lines follow, each describing a competition which should be scheduled. The $$$i$$$-th line contains two integers $$$k_i$$$ and $$$t_i$$$ ($$$2 \le k_i \le 5000$$$; $$$1 \le t_i \le 2$$$) — the parameters of the $$$i$$$-th competition.

If it is impossible to schedule all $$$n$$$ competitions on the next $$$m$$$ days so that there is at most one stage during each day, print -1. Otherwise, print $$$n$$$ integers. The $$$i$$$-th integer should represent the day when the first stage of the $$$i$$$-th competition is scheduled; days are numbered from $$$1$$$ to $$$m$$$. If there are multiple answers, print any of them.


A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example:  bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)");  bracket sequences ")(", "(" and ")" are not. You are given two strings $$$s$$$ and $$$a$$$, the string $$$s$$$ has length $$$n$$$, the string $$$a$$$ has length $$$n - 3$$$. The string $$$s$$$ is a bracket sequence (i. e. each element of this string is either an opening bracket character or a closing bracket character). The string $$$a$$$ is a binary string (i. e. each element of this string is either 1 or 0).The string $$$a$$$ imposes some constraints on the string $$$s$$$: for every $$$i$$$ such that $$$a_i$$$ is 1, the string $$$s_i s_{i+1} s_{i+2} s_{i+3}$$$ should be a regular bracket sequence. Characters of $$$a$$$ equal to 0 don't impose any constraints.Initially, the string $$$s$$$ may or may not meet these constraints. You can perform the following operation any number of times: replace some character of $$$s$$$ with its inverse (i. e. you can replace an opening bracket with a closing bracket, or vice versa).Determine if it is possible to change some characters in $$$s$$$ so that it meets all of the constraints, and if it is possible, calculate the minimum number of characters to be changed.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. Each test case consists of three lines. The first line contains one integer $$$n$$$ ($$$4 \le n \le 2 \cdot 10^5$$$). The second line contains the string $$$s$$$, consisting of exactly $$$n$$$ characters; each character of $$$s$$$ is either '(' or ')'. The third line contains the string $$$a$$$, consisting of exactly $$$n - 3$$$ characters; each character of $$$a$$$ is either '1' or '0'. Additional constraint on the input: the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

For each test case, print one integer: the minimum number of characters that need to be changed in $$$s$$$, or $$$-1$$$ if it is impossible.


A squad of $$$n$$$ warriors is defending a castle from a dragon attack. There are $$$m$$$ barricades between the castle and the dragon.The warriors are numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th warrior knows $$$k_i$$$ attacks: the $$$j$$$-th of them deals $$$a_{i,j}$$$ damage to the dragon and can only be applied if there are exactly $$$b_{i,j}$$$ barricades between the castle and the dragon.The warriors make turns one after another, starting from warrior $$$1$$$. After warrior $$$n$$$ makes his turn, the total damage to the dragon is calculated. The $$$i$$$-th warrior performs exactly one of three possible moves in his turn:  destroys one barricade (if there are any left);  deploys one of his $$$k_i$$$ attacks;  skips a turn. The total damage is the sum of damages dealt by the warriors who chose to deploy their attacks in their turn. What is the maximum total damage the warriors can deal to the dragon?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 3 \cdot 10^5$$$) — the number of warriors and the initial number of barricades. Then the descriptions of attacks for each warrior follow. The $$$i$$$-th description consists of three lines. The first line contains a single integer $$$k_i$$$ ($$$1 \le k_i \le m + 1$$$) — the number of attacks the $$$i$$$-th warrior knows. The second line contains $$$k_i$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,k_i}$$$ ($$$1 \le a_{i,j} \le 10^9$$$) — the damage of each attack. The third line contains $$$k_i$$$ integers $$$b_{i,1}, b_{i,2}, \dots, b_{i,k_i}$$$ ($$$0 \le b_{i,j} \le m$$$) — the required number of barricades for each attack. $$$b_{i,j}$$$ for the $$$i$$$-th warrior are pairwise distinct. The attacks are listed in the increasing order of the barricades requirement, so $$$b_{i,1} < b_{i,2} < \dots < b_{i,k_i}$$$. The sum of $$$k_i$$$ over all warriors doesn't exceed $$$3 \cdot 10^5$$$.

Print a single integer — the maximum total damage the warriors can deal to the dragon.

NoteIn the first example, the optimal choice is the following:   warrior $$$1$$$ destroys a barricade, now there are $$$3$$$ barricades left;  warrior $$$2$$$ deploys his first attack (he can do it because $$$b_{1,1}=3$$$, which is the current number of barricades). The total damage is $$$10$$$.If the first warrior used his attack or skipped his turn, then the second warrior would only be able to deploy his second attack. Thus, the total damage would be $$$2+5=7$$$ or $$$5$$$.In the second example, the first warrior skips his move, the second warrior skips his move and the third warrior deploys his only attack.In the third example, two equivalent options are:   both warriors deploy their second attacks;  the first warrior destroys one barricade and the second warrior deploys his first attack. Both options yield $$$30$$$ total damage.


Ira is developing a computer game. This game features randomized generation and difficulty of levels. To achieve randomized difficulty, some enemies in each level are randomly replaced with stronger ones.To describe how do the levels in the game look, let's introduce a coordinate system in such a way that $$$Ox$$$ axis goes from left to right, and $$$Oy$$$ axis goes from bottom to top. A level is a rectangle with opposite corners in points $$$(0, 0)$$$ and $$$(a, b)$$$. Each enemy's position is a point in this rectangle.As for now, Ira has implemented one type of enemy in the game, in two different versions — basic and upgraded. Both versions of enemies Ira has implemented fire laser rays in several directions:  basic enemies fire four laser rays in four directions: to the right (in the same direction as the vector $$$(1, 0)$$$), to the left (in the same direction as the vector $$$(-1, 0)$$$), up (in the same direction as the vector $$$(0, 1)$$$), and down (in the same direction as the vector $$$(0, -1)$$$);  upgraded enemies fire eight laser rays in eight directions: four directions listed for basic enemies, and four directions corresponding to vectors $$$(1, 1)$$$, $$$(1, -1)$$$, $$$(-1, 1)$$$, $$$(-1, -1)$$$. Laser rays pass through enemies and are blocked only by the borders of the level (sides of the rectangle that denotes the level). Enemies are unaffected by lasers.The level Ira is working on has $$$n$$$ enemies. The $$$i$$$-th enemy is in the point $$$(x_i, y_i)$$$, and it has a probability of $$$p_i$$$ to be upgraded (it's either upgraded with probability $$$p_i$$$, or basic with probability $$$1-p_i$$$). All these events are independent.Ira wants to estimate the expected difficulty. She considers that a good way to evaluate the difficulty of the level is to count the number of parts in which the level is divided by the laser rays. So, she wants to calculate the expected number of these parts.Help her to do the evaluation of the level!

The first line contains three integers $$$n$$$, $$$a$$$ and $$$b$$$ ($$$1 \le n \le 100$$$; $$$2 \le a, b \le 100$$$) — the number of enemies in the level and the dimensions of the level. Then $$$n$$$ lines follow, the $$$i$$$-th of them contains three integers $$$x_i$$$, $$$y_i$$$ and $$$p'_i$$$ ($$$1 \le x_i \le a - 1$$$; $$$1 \le y_i \le b - 1$$$; $$$1 \le p'_i \le 999999$$$), meaning that the $$$i$$$-th enemy is located at $$$(x_i, y_i)$$$ and has a probability of $$$\frac{p'_i}{10^6}$$$ to be upgraded. No two enemies are located in the same point.

Print one integer — the expected number of parts in which the lasers divide the level, taken modulo $$$998244353$$$ (i. e. let the expected number of parts be $$$\frac{x}{y}$$$ as an irreducible fraction; you have to print $$$x \cdot y^{-1} \bmod 998244353$$$, where $$$y^{-1}$$$ is a number such that $$$y \cdot y^{-1} \bmod 998244353 = 1$$$).

NoteExplanation to the first example:With probability $$$\frac{1}{2}$$$, the only enemy is not upgraded and the level looks like this ($$$4$$$ parts):  With probability $$$\frac{1}{2}$$$, the only enemy is upgraded and the level looks like this ($$$8$$$ parts):  So, the expected number of parts is $$$4 \cdot \frac{1}{2} + 8 \cdot \frac{1}{2} = 6$$$.


Polycarp plans to undergo a full physical examination at his local clinic. There are $$$n$$$ doctors, numbered from $$$1$$$ to $$$n$$$. The $$$i$$$-th doctor takes patients from minute $$$L_i$$$ to minute $$$R_i$$$, so Polycarp can visit him at any minute in this range. It takes each doctor exactly one minute to examine Polycarp's health.Polycarp wants to arrive at the clinic at some minute $$$x$$$ and visit all $$$n$$$ doctors in some order without waiting or visiting any doctor several times.More formally, he chooses an integer $$$x$$$ and a permutation $$$p_1, p_2, \dots, p_n$$$ (a sequence of $$$n$$$ integers from $$$1$$$ to $$$n$$$ such that each integer appears exactly once), then proceeds to visit:   doctor $$$p_1$$$ at minute $$$x$$$;  doctor $$$p_2$$$ at minute $$$x+1$$$;  ...  doctor $$$p_n$$$ at minute $$$x+n-1$$$. The $$$p_i$$$-th doctor should be able to take patients at minute $$$x+i-1$$$, so the following should hold: $$$L[p_i] \le x + i - 1 \le R[p_i]$$$.Determine if it's possible for Polycarp to choose such a minute $$$x$$$ and a permutation $$$p$$$ that he'll be able to visit all $$$n$$$ doctors in without waiting or visiting any doctor several times. If there are multiple answers, print any of them.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of testcases. Then the descriptions of $$$t$$$ testcases follow. The first line of the testcase contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of doctors. The second line of the testcase contains $$$n$$$ integers $$$L_1, L_2, \dots L_n$$$ ($$$1 \le L_i \le 10^9$$$). The third line of the testcase contains $$$n$$$ integers $$$R_1, R_2, \dots R_n$$$ ($$$L_i \le R_i \le 10^9$$$). The sum of $$$n$$$ over all testcases doesn't exceed $$$10^5$$$.

For each testcase print an answer. If there exists such a minute $$$x$$$ and a permutation $$$p$$$ that Polycarp is able to visit all $$$n$$$ doctors without waiting or visiting any doctor several times, then print $$$x$$$ in the first line and a permutation $$$p$$$ in the second line. If there are multiple answers, print any of them. Otherwise, print $$$-1$$$ in the only line.

NoteIn the third testcase it's impossible to visit all doctors, because Polycarp has to visit doctor $$$2$$$ at minute $$$2$$$ and doctor $$$1$$$ at minute $$$4$$$. However, that would require him to wait a minute between the visits, which is not allowed.In the fourth testcase all doctors take patients in the span of $$$2$$$ minutes. However, since there are three of them, Polycarp can't visit them all.


There are $$$n$$$ cities in Berland, and they are connected by two railroads — the Main railroad and the Auxiliary railroad. Each city has two railway stations, one connected to the Main railroad (called the Main station), and the other connected to the Auxiliary railroad.The railroads are identical in their structure. The Main railroad consists of $$$n-1$$$ railroad segments; the $$$i$$$-th railroad segment connects the Main station of the city $$$i$$$ with the Main station of the city $$$i+1$$$. Similarly, the Auxiliary railroad consists of $$$n-1$$$ railroad segments; the $$$i$$$-th railroad segment connects the Auxiliary station of the city $$$i$$$ with the Auxiliary station of the city $$$i+1$$$.These railroads are used to transfer different goods and resources from one city to another. In particular, the Ministry of Energetics is interested in using these railroads to transfer coal.The Ministry has estimated the following capabilities of the railroads:  for every $$$i \in [1, n-1]$$$, at most $$$a_i$$$ tons of coal per day can be transferred from the Main station $$$i$$$ to the Main station $$$i+1$$$ (only in this direction);  for every $$$i \in [1, n-1]$$$, at most $$$b_i$$$ tons of coal per day can be transferred from the Auxiliary station $$$i$$$ to the Auxiliary station $$$i+1$$$ (only in this direction);  for every $$$i \in [1, n]$$$, at most $$$c_i$$$ tons of coal per day can be transferred from the Main station $$$i$$$ to the Auxiliary station $$$i$$$, or in the opposite direction. To analyze the capacity of the whole railroad network, the Ministry requires a software that would process and answer queries of the following format:  calculate the maximum number of tons of coal that can be transferred per day from the Main station $$$l_i$$$ to the Main station $$$r_i$$$. Your task is to implement this software.

The first line contains one integer $$$n$$$ ($$$2 \le n \le 3 \cdot 10^5$$$) — the number of cities. The second line contains $$$n-1$$$ integers $$$a_1, a_2, \dots, a_{n-1}$$$ ($$$1 \le a_i \le 10^9$$$). The third line contains $$$n-1$$$ integers $$$b_1, b_2, \dots, b_{n-1}$$$ ($$$1 \le b_i \le 10^9$$$). The fourth line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_{n}$$$ ($$$1 \le c_i \le 10^9$$$). The fifth line contains one integer $$$q$$$ ($$$1 \le q \le 3 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ lines follow, the $$$i$$$-th line contains two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i < r_i \le n$$$) — the parameters of the $$$i$$$-th query.

Print $$$q$$$ integers, where the $$$i$$$-th integer should be the answer to the $$$i$$$-th query, i. e. the maximum number of tons of coal that can be transferred per day from the Main station $$$l_i$$$ to the Main station $$$r_i$$$.


You are given a book with $$$n$$$ chapters.Each chapter has a specified list of other chapters that need to be understood in order to understand this chapter. To understand a chapter, you must read it after you understand every chapter on its required list.Currently you don't understand any of the chapters. You are going to read the book from the beginning till the end repeatedly until you understand the whole book. Note that if you read a chapter at a moment when you don't understand some of the required chapters, you don't understand this chapter.Determine how many times you will read the book to understand every chapter, or determine that you will never understand every chapter no matter how many times you read the book.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 2\cdot10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 2\cdot10^5$$$) — number of chapters. Then $$$n$$$ lines follow. The $$$i$$$-th line begins with an integer $$$k_i$$$ ($$$0 \le k_i \le n-1$$$) — number of chapters required to understand the $$$i$$$-th chapter. Then $$$k_i$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i, k_i}$$$ ($$$1 \le a_{i, j} \le n, a_{i, j} \ne i, a_{i, j} \ne a_{i, l}$$$ for $$$j \ne l$$$) follow — the chapters required to understand the $$$i$$$-th chapter. It is guaranteed that the sum of $$$n$$$ and sum of $$$k_i$$$ over all testcases do not exceed $$$2\cdot10^5$$$.

For each test case, if the entire book can be understood, print how many times you will read it, otherwise print $$$-1$$$.

NoteIn the first example, we will understand chapters $$$\{2, 4\}$$$ in the first reading and chapters $$$\{1, 3\}$$$ in the second reading of the book.In the second example, every chapter requires the understanding of some other chapter, so it is impossible to understand the book.In the third example, every chapter requires only chapters that appear earlier in the book, so we can understand everything in one go.In the fourth example, we will understand chapters $$$\{2, 3, 4\}$$$ in the first reading and chapter $$$1$$$ in the second reading of the book.In the fifth example, we will understand one chapter in every reading from $$$5$$$ to $$$1$$$.


You are given a sequence $$$a$$$ of length $$$n$$$ consisting of $$$0$$$s and $$$1$$$s.You can perform the following operation on this sequence:   Pick an index $$$i$$$ from $$$1$$$ to $$$n-2$$$ (inclusive).  Change all of $$$a_{i}$$$, $$$a_{i+1}$$$, $$$a_{i+2}$$$ to $$$a_{i} \oplus a_{i+1} \oplus a_{i+2}$$$ simultaneously, where $$$\oplus$$$ denotes the bitwise XOR operation  Find a sequence of at most $$$n$$$ operations that changes all elements of $$$a$$$ to $$$0$$$s or report that it's impossible.We can prove that if there exists a sequence of operations of any length that changes all elements of $$$a$$$ to $$$0$$$s, then there is also such a sequence of length not greater than $$$n$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 2\cdot10^5$$$) — the length of $$$a$$$. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$a_i = 0$$$ or $$$a_i = 1$$$) — elements of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2\cdot10^5$$$.

For each test case, do the following:    if there is no way of making all the elements of $$$a$$$ equal to $$$0$$$ after performing the above operation some number of times, print "NO".  otherwise, in the first line print "YES", in the second line print $$$k$$$ ($$$0 \le k \le n$$$) — the number of operations that you want to perform on $$$a$$$, and in the third line print a sequence $$$b_1, b_2, \dots, b_k$$$ ($$$1 \le b_i \le n - 2$$$) — the indices on which the operation should be applied.  If there are multiple solutions, you may print any.

NoteIn the first example, the sequence contains only $$$0$$$s so we don't need to change anything.In the second example, we can transform $$$[1, 1, 1, 1, 0]$$$ to $$$[1, 1, 0, 0, 0]$$$ and then to $$$[0, 0, 0, 0, 0]$$$ by performing the operation on the third element of $$$a$$$ and then on the first element of $$$a$$$.In the third example, no matter whether we first perform the operation on the first or on the second element of $$$a$$$ we will get $$$[1, 1, 1, 1]$$$, which cannot be transformed to $$$[0, 0, 0, 0]$$$.


You are given a $$$1$$$ by $$$n$$$ pixel image. The $$$i$$$-th pixel of the image has color $$$a_i$$$. For each color, the number of pixels of that color is at most $$$20$$$.You can perform the following operation, which works like the bucket tool in paint programs, on this image:   pick a color — an integer from $$$1$$$ to $$$n$$$;  choose a pixel in the image;  for all pixels connected to the selected pixel, change their colors to the selected color (two pixels of the same color are considered connected if all the pixels between them have the same color as those two pixels). Compute the minimum number of operations needed to make all the pixels in the image have the same color.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 3\cdot10^3$$$) — the number of pixels in the image. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le n$$$) — the colors of the pixels in the image. Note: for each color, the number of pixels of that color is at most $$$20$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$3\cdot10^3$$$.

For each test case, print one integer: the minimum number of operations needed to make all the pixels in the image have the same color.

NoteIn the first example, the optimal solution is to apply the operation on the third pixel changing its color to $$$2$$$ and then to apply the operation on any pixel that has color $$$2$$$ changing its color and the color of all pixels connected to it to $$$1$$$. The sequence of operations is then: $$$[1, 2, 3, 2, 1] \to [1, 2, 2, 2, 1] \to [1, 1, 1, 1, 1]$$$.In the second example, we can either change the $$$1$$$s to $$$2$$$s in one operation or change the $$$2$$$s to $$$1$$$s also in one operation.In the third example, one possible way to make all the pixels have the same color is to apply the operation on the first, third and the fourth pixel each time changing its color to $$$2$$$.


There are currently $$$n$$$ hot topics numbered from $$$0$$$ to $$$n-1$$$ at your local bridge club and $$$2^n$$$ players numbered from $$$0$$$ to $$$2^n-1$$$. Each player holds a different set of views on those $$$n$$$ topics, more specifically, the $$$i$$$-th player holds a positive view on the $$$j$$$-th topic if $$$i\ \&\ 2^j > 0$$$, and a negative view otherwise. Here $$$\&$$$ denotes the bitwise AND operation.You are going to organize a bridge tournament capable of accommodating at most $$$k$$$ pairs of players (bridge is played in teams of two people). You can select teams arbitrarily while each player is in at most one team, but there is one catch: two players cannot be in the same pair if they disagree on $$$2$$$ or more of those $$$n$$$ topics, as they would argue too much during the play.You know that the $$$i$$$-th player will pay you $$$a_i$$$ dollars if they play in this tournament. Compute the maximum amount of money that you can earn if you pair the players in your club optimally.

The first line contains two integers $$$n$$$, $$$k$$$ ($$$1 \le n \le 20$$$, $$$1 \le k \le 200$$$) — the number of hot topics and the number of pairs of players that your tournament can accommodate. The second line contains $$$2^n$$$ integers $$$a_0, a_1, \dots, a_{2^n-1}$$$ ($$$0 \le a_i \le 10^6$$$) — the amounts of money that the players will pay to play in the tournament.

Print one integer: the maximum amount of money that you can earn if you pair the players in your club optimally under the above conditions.

NoteIn the first example, the best we can do is to pair together the $$$0$$$-th player and the $$$2$$$-nd player resulting in earnings of $$$8 + 5 = 13$$$ dollars. Although pairing the $$$0$$$-th player with the $$$5$$$-th player would give us $$$8 + 10 = 18$$$ dollars, we cannot do this because those two players disagree on $$$2$$$ of the $$$3$$$ hot topics.In the second example, we can pair the $$$0$$$-th player with the $$$1$$$-st player and pair the $$$2$$$-nd player with the $$$3$$$-rd player resulting in earnings of $$$7 + 4 + 5 + 7 = 23$$$ dollars.


You are given a strictly convex polygon with $$$n$$$ vertices.You will make $$$k$$$ cuts that meet the following conditions:   each cut is a segment that connects two different nonadjacent vertices;  two cuts can intersect only at vertices of the polygon. Your task is to maximize the area of the smallest region that will be formed by the polygon and those $$$k$$$ cuts.

The first line contains two integers $$$n$$$, $$$k$$$ ($$$3 \le n \le 200$$$, $$$0 \le k \le n-3$$$). The following $$$n$$$ lines describe vertices of the polygon in anticlockwise direction. The $$$i$$$-th line contains two integers $$$x_i$$$, $$$y_i$$$ ($$$|x_i|, |y_i| \le 10^8$$$) — the coordinates of the $$$i$$$-th vertex. It is guaranteed that the polygon is convex and that no two adjacent sides are parallel.

Print one integer: the maximum possible area of the smallest region after making $$$k$$$ cuts multiplied by $$$2$$$.


There are $$$n$$$ cities in a row numbered from $$$1$$$ to $$$n$$$.The cities will be building broadcasting stations. The station in the $$$i$$$-th city has height $$$h_i$$$ and range $$$w_i$$$. It can broadcast information to city $$$j$$$ if the following constraints are met:   $$$i \le j \le w_i$$$, and  for each $$$k$$$ such that $$$i < k \le j$$$, the following condition holds: $$$h_k < h_i$$$.  In other words, the station in city $$$i$$$ can broadcast information to city $$$j$$$ if $$$j \ge i$$$, $$$j$$$ is in the range of $$$i$$$-th station, and $$$i$$$ is strictly highest on the range from $$$i$$$ to $$$j$$$ (including city $$$j$$$).At the beginning, for every city $$$i$$$, $$$h_i = 0$$$ and $$$w_i = i$$$.Then $$$q$$$ events will take place. During $$$i$$$-th event one of the following will happen:   City $$$c_i$$$ will rebuild its station so that its height will be strictly highest among all stations and $$$w_{c_i}$$$ will be set to $$$g_i$$$.  Let $$$b_j$$$ be the number of stations that can broadcast information to city $$$j$$$. Print the sum of $$$b_j$$$ over all $$$j$$$ satisfying $$$l_i \le j \le r_i$$$. Your task is to react to all events and print answers to all queries.

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$1 \le n, q \le 2\cdot10^5$$$) — number of cities and number of events. Then $$$q$$$ lines follow. The $$$i$$$-th line begins with an integer $$$p_i$$$ ($$$p_i = 1$$$ or $$$p_i = 2$$$). If $$$p_i = 1$$$ a station will be rebuilt. Then two integers $$$c_i$$$ and $$$g_i$$$ ($$$1 \le c_i \le g_i \le n$$$) follow — the city in which the station is rebuilt and its new broadcasting range. If $$$p_i = 2$$$ you are given a query. Then two integers $$$l_i$$$ and $$$r_i$$$ ($$$1 \le l_i \le r_i \le n$$$) follow — the range of cities in the query.

For each query, print in a single line the sum of $$$b_j$$$ over the given interval.

NoteIn the first test case, only station $$$1$$$ reaches city $$$1$$$ before and after it is rebuilt.In the second test case, after each rebuild, the array $$$b$$$ looks as follows:   $$$[1, 1, 1, 2, 1]$$$;  $$$[1, 2, 2, 3, 2]$$$;  $$$[1, 2, 2, 1, 2]$$$;  $$$[1, 1, 2, 1, 2]$$$;  $$$[1, 1, 2, 1, 1]$$$.


You are given a digital clock with $$$n$$$ digits. Each digit shows an integer from $$$0$$$ to $$$9$$$, so the whole clock shows an integer from $$$0$$$ to $$$10^n-1$$$. The clock will show leading zeroes if the number is smaller than $$$10^{n-1}$$$.You want the clock to show $$$0$$$ with as few operations as possible. In an operation, you can do one of the following:   decrease the number on the clock by $$$1$$$, or  swap two digits (you can choose which digits to swap, and they don't have to be adjacent). Your task is to determine the minimum number of operations needed to make the clock show $$$0$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^3$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 100$$$) — number of digits on the clock. The second line of each test case contains a string of $$$n$$$ digits $$$s_1, s_2, \ldots, s_n$$$ ($$$0 \le s_1, s_2, \ldots, s_n \le 9$$$) — the number on the clock. Note: If the number is smaller than $$$10^{n-1}$$$ the clock will show leading zeroes.

For each test case, print one integer: the minimum number of operations needed to make the clock show $$$0$$$.

NoteIn the first example, it's optimal to just decrease the number $$$7$$$ times.In the second example, we can first swap the first and last position and then decrease the number by $$$1$$$.In the third example, the clock already shows $$$0$$$, so we don't have to perform any operations.


You are given two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$. Array $$$a$$$ contains each odd integer from $$$1$$$ to $$$2n$$$ in an arbitrary order, and array $$$b$$$ contains each even integer from $$$1$$$ to $$$2n$$$ in an arbitrary order.You can perform the following operation on those arrays:   choose one of the two arrays  pick an index $$$i$$$ from $$$1$$$ to $$$n-1$$$  swap the $$$i$$$-th and the $$$(i+1)$$$-th elements of the chosen array  Compute the minimum number of operations needed to make array $$$a$$$ lexicographically smaller than array $$$b$$$.For two different arrays $$$x$$$ and $$$y$$$ of the same length $$$n$$$, we say that $$$x$$$ is lexicographically smaller than $$$y$$$ if in the first position where $$$x$$$ and $$$y$$$ differ, the array $$$x$$$ has a smaller element than the corresponding element in $$$y$$$.

Each test contains multiple test cases. The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 10^4$$$). The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of the arrays. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \le a_i \le 2n$$$, all $$$a_i$$$ are odd and pairwise distinct) — array $$$a$$$. The third line of each test case contains $$$n$$$ integers $$$b_1, b_2, \ldots, b_n$$$ ($$$1 \le b_i \le 2n$$$, all $$$b_i$$$ are even and pairwise distinct) — array $$$b$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$10^5$$$.

For each test case, print one integer: the minimum number of operations needed to make array $$$a$$$ lexicographically smaller than array $$$b$$$. We can show that an answer always exists.

NoteIn the first example, the array $$$a$$$ is already lexicographically smaller than array $$$b$$$, so no operations are required.In the second example, we can swap $$$5$$$ and $$$3$$$ and then swap $$$2$$$ and $$$4$$$, which results in $$$[3, 5, 1]$$$ and $$$[4, 2, 6]$$$. Another correct way is to swap $$$3$$$ and $$$1$$$ and then swap $$$5$$$ and $$$1$$$, which results in $$$[1, 5, 3]$$$ and $$$[2, 4, 6]$$$. Yet another correct way is to swap $$$4$$$ and $$$6$$$ and then swap $$$2$$$ and $$$6$$$, which results in $$$[5, 3, 1]$$$ and $$$[6, 2, 4]$$$.


A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.You are given an integer $$$n$$$. Your goal is to construct and print exactly $$$n$$$ different regular bracket sequences of length $$$2n$$$.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 50$$$) — the number of test cases. Each test case consists of one line containing one integer $$$n$$$ ($$$1 \le n \le 50$$$).

For each test case, print $$$n$$$ lines, each containing a regular bracket sequence of length exactly $$$2n$$$. All bracket sequences you output for a testcase should be different (though they may repeat in different test cases). If there are multiple answers, print any of them. It can be shown that it's always possible.


You are given four integer values $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$.Check if there exists a string that contains:   $$$a$$$ letters 'A';  $$$b$$$ letters 'B';  $$$c$$$ letters 'C';  no other letters;  exactly $$$m$$$ pairs of adjacent equal letters (exactly $$$m$$$ such positions $$$i$$$ that the $$$i$$$-th letter is equal to the $$$(i+1)$$$-th one).

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of testcases. Each of the next $$$t$$$ lines contains the description of the testcase — four integers $$$a$$$, $$$b$$$, $$$c$$$ and $$$m$$$ ($$$1 \le a, b, c \le 10^8$$$; $$$0 \le m \le 10^8$$$).

For each testcase print "YES" if there exists a string that satisfies all the requirements. Print "NO" if there are no such strings. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

NoteIn the first testcase strings "ABCAB" or "BCABA" satisfy the requirements. There exist other possible strings.In the second testcase there's no way to put adjacent equal letters if there's no letter that appears at least twice.In the third testcase string "CABBCC" satisfies the requirements. There exist other possible strings.


Ivan is playing yet another roguelike computer game. He controls a single hero in the game. The hero has $$$n$$$ equipment slots. There is a list of $$$c_i$$$ items for the $$$i$$$-th slot, the $$$j$$$-th of them increases the hero strength by $$$a_{i,j}$$$. The items for each slot are pairwise distinct and are listed in the increasing order of their strength increase. So, $$$a_{i,1} < a_{i,2} < \dots < a_{i,c_i}$$$.For each slot Ivan chooses exactly one item. Let the chosen item for the $$$i$$$-th slot be the $$$b_i$$$-th item in the corresponding list. The sequence of choices $$$[b_1, b_2, \dots, b_n]$$$ is called a build.The strength of a build is the sum of the strength increases of the items in it. Some builds are banned from the game. There is a list of $$$m$$$ pairwise distinct banned builds. It's guaranteed that there's at least one build that's not banned.What is the build with the maximum strength that is not banned from the game? If there are multiple builds with maximum strength, print any of them.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10$$$) — the number of equipment slots. The $$$i$$$-th of the next $$$n$$$ lines contains the description of the items for the $$$i$$$-th slot. First, one integer $$$c_i$$$ ($$$1 \le c_i \le 2 \cdot 10^5$$$) — the number of items for the $$$i$$$-th slot. Then $$$c_i$$$ integers $$$a_{i,1}, a_{i,2}, \dots, a_{i,c_i}$$$ ($$$1 \le a_{i,1} < a_{i,2} < \dots < a_{i,c_i} \le 10^8$$$). The sum of $$$c_i$$$ doesn't exceed $$$2 \cdot 10^5$$$. The next line contains a single integer $$$m$$$ ($$$0 \le m \le 10^5$$$) — the number of banned builds. Each of the next $$$m$$$ lines contains a description of a banned build — a sequence of $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le c_i$$$). The builds are pairwise distinct, and there's at least one build that's not banned.

Print the build with the maximum strength that is not banned from the game. If there are multiple builds with maximum strength, print any of them.


A matrix of size $$$n \times m$$$, such that each cell of it contains either $$$0$$$ or $$$1$$$, is considered beautiful if the sum in every contiguous submatrix of size $$$2 \times 2$$$ is exactly $$$2$$$, i. e. every "square" of size $$$2 \times 2$$$ contains exactly two $$$1$$$'s and exactly two $$$0$$$'s.You are given a matrix of size $$$n \times m$$$. Initially each cell of this matrix is empty. Let's denote the cell on the intersection of the $$$x$$$-th row and the $$$y$$$-th column as $$$(x, y)$$$. You have to process the queries of three types:  $$$x$$$ $$$y$$$ $$$-1$$$ — clear the cell $$$(x, y)$$$, if there was a number in it;  $$$x$$$ $$$y$$$ $$$0$$$ — write the number $$$0$$$ in the cell $$$(x, y)$$$, overwriting the number that was there previously (if any);  $$$x$$$ $$$y$$$ $$$1$$$ — write the number $$$1$$$ in the cell $$$(x, y)$$$, overwriting the number that was there previously (if any). After each query, print the number of ways to fill the empty cells of the matrix so that the resulting matrix is beautiful. Since the answers can be large, print them modulo $$$998244353$$$.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$2 \le n, m \le 10^6$$$; $$$1 \le k \le 3 \cdot 10^5$$$) — the number of rows in the matrix, the number of columns, and the number of queries, respectively. Then $$$k$$$ lines follow, the $$$i$$$-th of them contains three integers $$$x_i$$$, $$$y_i$$$, $$$t_i$$$ ($$$1 \le x_i \le n$$$; $$$1 \le y_i \le m$$$; $$$-1 \le t_i \le 1$$$) — the parameters for the $$$i$$$-th query.

For each query, print one integer — the number of ways to fill the empty cells of the matrix after the respective query, taken modulo $$$998244353$$$.


A subarray of array $$$a$$$ from index $$$l$$$ to the index $$$r$$$ is the array $$$[a_l, a_{l+1}, \dots, a_{r}]$$$. The number of occurrences of the array $$$b$$$ in the array $$$a$$$ is the number of subarrays of $$$a$$$ such that they are equal to $$$b$$$.You are given $$$n$$$ arrays $$$A_1, A_2, \dots, A_n$$$; the elements of these arrays are integers from $$$1$$$ to $$$k$$$. You have to build an array $$$a$$$ consisting of $$$m$$$ integers from $$$1$$$ to $$$k$$$ in such a way that, for every given subarray $$$A_i$$$, the number of occurrences of $$$A_i$$$ in the array $$$a$$$ is not less than the number of occurrences of each non-empty subarray of $$$A_i$$$ in $$$a$$$. Note that if $$$A_i$$$ doesn't occur in $$$a$$$, and no subarray of $$$A_i$$$ occurs in $$$a$$$, this condition is still met for $$$A_i$$$.Your task is to calculate the number of different arrays $$$a$$$ you can build, and print it modulo $$$998244353$$$.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n, m, k \le 3 \cdot 10^5$$$) — the number of the given arrays, the desired length of the array $$$a$$$, and the upper bound on the values in the arrays. Then $$$n$$$ lines follow. The $$$i$$$-th line represents the array $$$A_i$$$. The first integer in the $$$i$$$-th line is $$$c_i$$$ ($$$1 \le c_i \le m$$$) — the number of elements in $$$A_i$$$; then, $$$c_i$$$ integers from $$$1$$$ to $$$k$$$ follow — the elements of the array $$$A_i$$$. Additional constraint on the input: $$$\sum\limits_{i=1}^n c_i \le 3 \cdot 10^5$$$; i. e., the number of elements in the given arrays in total does not exceed $$$3 \cdot 10^5$$$.

Print one integer — the number of different arrays $$$a$$$ you can build, taken modulo $$$998244353$$$.


Andi and Budi were given an assignment to tidy up their bookshelf of $$$n$$$ books. Each book is represented by the book title — a string $$$s_i$$$ numbered from $$$1$$$ to $$$n$$$, each with length $$$m$$$. Andi really wants to sort the book lexicographically ascending, while Budi wants to sort it lexicographically descending.Settling their fight, they decided to combine their idea and sort it asc-desc-endingly, where the odd-indexed characters will be compared ascendingly, and the even-indexed characters will be compared descendingly.A string $$$a$$$ occurs before a string $$$b$$$ in asc-desc-ending order if and only if in the first position where $$$a$$$ and $$$b$$$ differ, the following holds:  if it is an odd position, the string $$$a$$$ has a letter that appears earlier in the alphabet than the corresponding letter in $$$b$$$;  if it is an even position, the string $$$a$$$ has a letter that appears later in the alphabet than the corresponding letter in $$$b$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \cdot m \leq 10^6$$$). The $$$i$$$-th of the next $$$n$$$ lines contains a string $$$s_i$$$ consisting of $$$m$$$ uppercase Latin letters — the book title. The strings are pairwise distinct.

Output $$$n$$$ integers — the indices of the strings after they are sorted asc-desc-endingly.

NoteThe following illustrates the first example.


Mr. Chanek lives in a city represented as a plane. He wants to build an amusement park in the shape of a circle of radius $$$r$$$. The circle must touch the origin (point $$$(0, 0)$$$).There are $$$n$$$ bird habitats that can be a photo spot for the tourists in the park. The $$$i$$$-th bird habitat is at point $$$p_i = (x_i, y_i)$$$. Find the minimum radius $$$r$$$ of a park with at least $$$k$$$ bird habitats inside. A point is considered to be inside the park if and only if the distance between $$$p_i$$$ and the center of the park is less than or equal to the radius of the park. Note that the center and the radius of the park do not need to be integers.In this problem, it is guaranteed that the given input always has a solution with $$$r \leq 2 \cdot 10^5$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \leq n \leq 10^5$$$, $$$1 \leq k \leq n$$$) — the number of bird habitats in the city and the number of bird habitats required to be inside the park. The $$$i$$$-th of the next $$$n$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$0 \leq |x_i|, |y_i| \leq 10^5$$$) — the position of the $$$i$$$-th bird habitat.

Output a single real number $$$r$$$ denoting the minimum radius of a park with at least $$$k$$$ bird habitats inside. It is guaranteed that the given input always has a solution with $$$r \leq 2 \cdot 10^5$$$. 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, Mr. Chanek can put the center of the park at $$$(-3, -1)$$$ with radius $$$\sqrt{10} \approx 3.162$$$. It can be proven this is the minimum $$$r$$$.The following illustrates the first example. The blue points represent bird habitats and the red circle represents the amusement park.


Denote a cyclic sequence of size $$$n$$$ as an array $$$s$$$ such that $$$s_n$$$ is adjacent to $$$s_1$$$. The segment $$$s[r, l]$$$ where $$$l < r$$$ is the concatenation of $$$s[r, n]$$$ and $$$s[1, l]$$$.You are given an array $$$a$$$ consisting of $$$n$$$ integers. Define $$$b$$$ as the cyclic sequence obtained from concatenating $$$m$$$ copies of $$$a$$$. Note that $$$b$$$ has size $$$n \cdot m$$$.You are given an integer $$$k$$$ where $$$k = 1$$$ or $$$k$$$ is a prime number. Find the number of different segments in $$$b$$$ where the sum of elements in the segment is divisible by $$$k$$$.Two segments are considered different if the set of indices of the segments are different. For example, when $$$n = 3$$$ and $$$m = 2$$$, the set of indices for segment $$$s[2, 5]$$$ is $$$\{2, 3, 4, 5\}$$$, and for segment $$$s[5, 2]$$$ is $$$\{5, 6, 1, 2\}$$$. In particular, the segments $$$s[1, 6], s[2,1], \ldots, s[6, 5]$$$ are considered as the same segment.Output the answer modulo $$$10^9 + 7$$$.

The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \leq n, m, k \leq 2 \cdot 10^5$$$, $$$k = 1$$$ or $$$k$$$ is a prime number). The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 2 \cdot 10^5$$$).

Output an integer denoting the number of different segments in $$$b$$$ where the sum of elements in the segment is divisible by $$$k$$$, modulo $$$10^9 + 7$$$.

NoteIn the first example, all valid segments are $$$[1,4]$$$, $$$[2, 3]$$$, $$$[3, 5]$$$, and $$$[4, 2]$$$.In the second example, one of the valid segments is $$$[1, 5]$$$.


Recently, Petya learned about a new game "Slay the Dragon". As the name suggests, the player will have to fight with dragons. To defeat a dragon, you have to kill it and defend your castle. To do this, the player has a squad of $$$n$$$ heroes, the strength of the $$$i$$$-th hero is equal to $$$a_i$$$.According to the rules of the game, exactly one hero should go kill the dragon, all the others will defend the castle. If the dragon's defense is equal to $$$x$$$, then you have to send a hero with a strength of at least $$$x$$$ to kill it. If the dragon's attack power is $$$y$$$, then the total strength of the heroes defending the castle should be at least $$$y$$$.The player can increase the strength of any hero by $$$1$$$ for one gold coin. This operation can be done any number of times.There are $$$m$$$ dragons in the game, the $$$i$$$-th of them has defense equal to $$$x_i$$$ and attack power equal to $$$y_i$$$. Petya was wondering what is the minimum number of coins he needs to spend to defeat the $$$i$$$-th dragon.Note that the task is solved independently for each dragon (improvements are not saved).

The first line contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — number of heroes. The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{12}$$$), where $$$a_i$$$ is the strength of the $$$i$$$-th hero. The third line contains a single integer $$$m$$$ ($$$1 \le m \le 2 \cdot 10^5$$$) — the number of dragons. The next $$$m$$$ lines contain two integers each, $$$x_i$$$ and $$$y_i$$$ ($$$1 \le x_i \le 10^{12}; 1 \le y_i \le 10^{18}$$$) — defense and attack power of the $$$i$$$-th dragon.

Print $$$m$$$ lines, $$$i$$$-th of which contains a single integer — the minimum number of coins that should be spent to defeat the $$$i$$$-th dragon.

NoteTo defeat the first dragon, you can increase the strength of the third hero by $$$1$$$, then the strength of the heroes will be equal to $$$[3, 6, 3, 3]$$$. To kill the dragon, you can choose the first hero.To defeat the second dragon, you can increase the forces of the second and third heroes by $$$1$$$, then the strength of the heroes will be equal to $$$[3, 7, 3, 3]$$$. To kill the dragon, you can choose a second hero.To defeat the third dragon, you can increase the strength of all the heroes by $$$1$$$, then the strength of the heroes will be equal to $$$[4, 7, 3, 4]$$$. To kill the dragon, you can choose a fourth hero.To defeat the fourth dragon, you don't need to improve the heroes and choose a third hero to kill the dragon.To defeat the fifth dragon, you can increase the strength of the second hero by $$$2$$$, then the strength of the heroes will be equal to $$$[3, 8, 2, 3]$$$. To kill the dragon, you can choose a second hero.


Mr. Chanek has an integer represented by a string $$$s$$$. Zero or more digits have been erased and are denoted by the character _. There are also zero or more digits marked by the character X, meaning they're the same digit.Mr. Chanek wants to count the number of possible integer $$$s$$$, where $$$s$$$ is divisible by $$$25$$$. Of course, $$$s$$$ must not contain any leading zero. He can replace the character _ with any digit. He can also replace the character X with any digit, but it must be the same for every character X.As a note, a leading zero is any 0 digit that comes before the first nonzero digit in a number string in positional notation. For example, 0025 has two leading zeroes. An exception is the integer zero, (0 has no leading zero, but 0000 has three leading zeroes).

One line containing the string $$$s$$$ ($$$1 \leq |s| \leq 8$$$). The string $$$s$$$ consists of the characters 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, _, and X.

Output an integer denoting the number of possible integer $$$s$$$.

NoteIn the first example, the only possible $$$s$$$ is $$$25$$$.In the second and third example, $$$s \in \{100, 200,300,400,500,600,700,800,900\}$$$.In the fifth example, all possible $$$s$$$ will have at least one leading zero.


There is a city park represented as a tree with $$$n$$$ attractions as its vertices and $$$n - 1$$$ rails as its edges. The $$$i$$$-th attraction has happiness value $$$a_i$$$.Each rail has a color. It is either black if $$$t_i = 0$$$, or white if $$$t_i = 1$$$. Black trains only operate on a black rail track, and white trains only operate on a white rail track. If you are previously on a black train and want to ride a white train, or you are previously on a white train and want to ride a black train, you need to use $$$1$$$ ticket.The path of a tour must be a simple path — it must not visit an attraction more than once. You do not need a ticket the first time you board a train. You only have $$$k$$$ tickets, meaning you can only switch train types at most $$$k$$$ times. In particular, you do not need a ticket to go through a path consisting of one rail color.Define $$$f(u, v)$$$ as the sum of happiness values of the attractions in the tour $$$(u, v)$$$, which is a simple path that starts at the $$$u$$$-th attraction and ends at the $$$v$$$-th attraction. Find the sum of $$$f(u,v)$$$ for all valid tours $$$(u, v)$$$ ($$$1 \leq u \leq v \leq n$$$) that does not need more than $$$k$$$ tickets, modulo $$$10^9 + 7$$$.

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 2 \cdot 10^5$$$, $$$0 \leq k \leq n-1$$$) — the number of attractions in the city park and the number of tickets you have. The second line contains $$$n$$$ integers $$$a_1, a_2,\ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$) — the happiness value of each attraction. The $$$i$$$-th of the next $$$n - 1$$$ lines contains three integers $$$u_i$$$, $$$v_i$$$, and $$$t_i$$$ ($$$1 \leq u_i, v_i \leq n$$$, $$$0 \leq t_i \leq 1$$$) — an edge between vertices $$$u_i$$$ and $$$v_i$$$ with color $$$t_i$$$. The given edges form a tree.

Output an integer denoting the total happiness value for all valid tours $$$(u, v)$$$ ($$$1 \leq u \leq v \leq n$$$), modulo $$$10^9 + 7$$$.


Mr. Chanek opened a letter from his fellow, who is currently studying at Singanesia. Here is what it says.Define an array $$$b$$$ ($$$0 \leq b_i < k$$$) with $$$n$$$ integers. While there exists a pair $$$(i, j)$$$ such that $$$b_i \ne b_j$$$, do the following operation:  Randomly pick a number $$$i$$$ satisfying $$$0 \leq i < n$$$. Note that each number $$$i$$$ has a probability of $$$\frac{1}{n}$$$ to be picked.  Randomly Pick a number $$$j$$$ satisfying $$$0 \leq j < k$$$.  Change the value of $$$b_i$$$ to $$$j$$$. It is possible for $$$b_i$$$ to be changed to the same value. Denote $$$f(b)$$$ as the expected number of operations done to $$$b$$$ until all elements of $$$b$$$ are equal. You are given two integers $$$n$$$ and $$$k$$$, and an array $$$a$$$ ($$$-1 \leq a_i < k$$$) of $$$n$$$ integers. For every index $$$i$$$ with $$$a_i = -1$$$, replace $$$a_i$$$ with a random number $$$j$$$ satisfying $$$0 \leq j < k$$$. Let $$$c$$$ be the number of occurrences of $$$-1$$$ in $$$a$$$. There are $$$k^c$$$ possibilites of $$$a$$$ after the replacement, each with equal probability of being the final array.Find the expected value of $$$f(a)$$$ modulo $$$10^9 + 7$$$. Formally, let $$$M = 10^9 + 7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$\frac{p}{q}$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q \not \equiv 0 \pmod{M}$$$. Output the integer equal to $$$p \cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \le x < M$$$ and $$$x \cdot q \equiv p \pmod{M}$$$.After reading the letter, Mr. Chanek gave the task to you. Solve it for the sake of their friendship!

The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \leq n \leq 10^5$$$, $$$2 \leq k \leq 10^9$$$).  The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$-1 \leq a_i < k$$$).

Output an integer denoting the expected value of $$$f(a)$$$ modulo $$$10^9 + 7$$$.


Chanek Jones is back, helping his long-lost relative Indiana Jones, to find a secret treasure in a maze buried below a desert full of illusions.The map of the labyrinth forms a tree with $$$n$$$ rooms numbered from $$$1$$$ to $$$n$$$ and $$$n - 1$$$ tunnels connecting them such that it is possible to travel between each pair of rooms through several tunnels.The $$$i$$$-th room ($$$1 \leq i \leq n$$$) has $$$a_i$$$ illusion rate. To go from the $$$x$$$-th room to the $$$y$$$-th room, there must exist a tunnel between $$$x$$$ and $$$y$$$, and it takes $$$\max(|a_x + a_y|, |a_x - a_y|)$$$ energy. $$$|z|$$$ denotes the absolute value of $$$z$$$.To prevent grave robbers, the maze can change the illusion rate of any room in it. Chanek and Indiana would ask $$$q$$$ queries.There are two types of queries to be done:  $$$1\ u\ c$$$ — The illusion rate of the $$$x$$$-th room is changed to $$$c$$$ ($$$1 \leq u \leq n$$$, $$$0 \leq |c| \leq 10^9$$$).  $$$2\ u\ v$$$ — Chanek and Indiana ask you the minimum sum of energy needed to take the secret treasure at room $$$v$$$ if they are initially at room $$$u$$$ ($$$1 \leq u, v \leq n$$$). Help them, so you can get a portion of the treasure!

The first line contains two integers $$$n$$$ and $$$q$$$ ($$$2 \leq n \leq 10^5$$$, $$$1 \leq q \leq 10^5$$$) — the number of rooms in the maze and the number of queries. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq |a_i| \leq 10^9$$$) — inital illusion rate of each room. The $$$i$$$-th of the next $$$n-1$$$ lines contains two integers $$$s_i$$$ and $$$t_i$$$ ($$$1 \leq s_i, t_i \leq n$$$), meaning there is a tunnel connecting $$$s_i$$$-th room and $$$t_i$$$-th room. The given edges form a tree. The next $$$q$$$ lines contain the query as described. The given queries are valid.

For each type $$$2$$$ query, output a line containing an integer — the minimum sum of energy needed for Chanek and Indiana to take the secret treasure.

Note  In the first query, their movement from the $$$1$$$-st to the $$$2$$$-nd room is as follows.  $$$1 \rightarrow 5$$$ — takes $$$\max(|10 + 4|, |10 - 4|) = 14$$$ energy.  $$$5 \rightarrow 6$$$ — takes $$$\max(|4 + (-6)|, |4 - (-6)|) = 10$$$ energy.  $$$6 \rightarrow 2$$$ — takes $$$\max(|-6 + (-9)|, |-6 - (-9)|) = 15$$$ energy.  In total, it takes $$$39$$$ energy.In the second query, the illusion rate of the $$$1$$$-st room changes from $$$10$$$ to $$$-3$$$.In the third query, their movement from the $$$1$$$-st to the $$$2$$$-nd room is as follows.  $$$1 \rightarrow 5$$$ — takes $$$\max(|-3 + 4|, |-3 - 4|) = 7$$$ energy.  $$$5 \rightarrow 6$$$ — takes $$$\max(|4 + (-6)|, |4 - (-6)|) = 10$$$ energy.  $$$6 \rightarrow 2$$$ — takes $$$\max(|-6 + (-9)|, |-6 - (-9)|) = 15$$$ energy. Now, it takes $$$32$$$ energy.


Mr. Chanek has a new game called Dropping Balls. Initially, Mr. Chanek has a grid $$$a$$$ of size $$$n \times m$$$Each cell $$$(x,y)$$$ contains an integer $$$a_{x,y}$$$ denoting the direction of how the ball will move.  $$$a_{x,y}=1$$$ — the ball will move to the right (the next cell is $$$(x, y + 1)$$$);  $$$a_{x,y}=2$$$ — the ball will move to the bottom (the next cell is $$$(x + 1, y)$$$);  $$$a_{x,y}=3$$$ — the ball will move to the left (the next cell is $$$(x, y - 1)$$$). Every time a ball leaves a cell $$$(x,y)$$$, the integer $$$a_{x,y}$$$ will change to $$$2$$$. Mr. Chanek will drop $$$k$$$ balls sequentially, each starting from the first row, and on the $$$c_1, c_2, \dots, c_k$$$-th ($$$1 \leq c_i \leq m$$$) columns.Determine in which column each ball will end up in (position of the ball after leaving the grid).

The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$1 \leq n, m \leq 1000$$$, $$$1 \leq k \leq 10^5$$$) — the size of the grid and the number of balls dropped by Mr. Chanek. The $$$i$$$-th of the next $$$n$$$ lines contains $$$m$$$ integers $$$a_{i,1},a_{i,2},\ldots,a_{i,m}$$$ ($$$1 \leq a_{i,j} \leq 3$$$). It will satisfy $$$a_{i, 1} \ne 3$$$ and $$$a_{i, m} \ne 1$$$. The next line contains $$$k$$$ integers $$$c_1, c_2, \ldots, c_k$$$ ($$$1 \leq c_i \leq m$$$) — the balls' column positions dropped by Mr. Chanek sequentially.

Output $$$k$$$ integers — the $$$i$$$-th integer denoting the column where the $$$i$$$-th ball will end.

NoteIn the first example, the first ball will drop as follows. Note that the cell $$$(1, 1)$$$ will change direction to the bottom direction.  The second and third balls will drop as follows.   All balls will be dropped from the first row and on the $$$c_1, c_2, \dots, c_k$$$-th columns respectively. A ball will stop dropping once it leaves the grid.


Mr. Chanek wants to knit a batik, a traditional cloth from Indonesia. The cloth forms a grid $$$a$$$ with size $$$n \times m$$$. There are $$$k$$$ colors, and each cell in the grid can be one of the $$$k$$$ colors.Define a sub-rectangle as an ordered pair of two cells $$$((x_1, y_1), (x_2, y_2))$$$, denoting the top-left cell and bottom-right cell (inclusively) of a sub-rectangle in $$$a$$$. Two sub-rectangles $$$((x_1, y_1), (x_2, y_2))$$$ and $$$((x_3, y_3), (x_4, y_4))$$$ have the same pattern if and only if the following holds:   they have the same width ($$$x_2 - x_1 = x_4 - x_3$$$);  they have the same height ($$$y_2 - y_1 = y_4 - y_3$$$);  for every pair $$$(i, j)$$$ where $$$0 \leq i \leq x_2 - x_1$$$ and $$$0 \leq j \leq y_2 - y_1$$$, the color of cells $$$(x_1 + i, y_1 + j)$$$ and $$$(x_3 + i, y_3 + j)$$$ are equal. Count the number of possible batik color combinations, such that the subrectangles $$$((a_x, a_y),(a_x + r - 1, a_y + c - 1))$$$ and $$$((b_x, b_y),(b_x + r - 1, b_y + c - 1))$$$ have the same pattern.Output the answer modulo $$$10^9 + 7$$$.

The first line contains five integers $$$n$$$, $$$m$$$, $$$k$$$, $$$r$$$, and $$$c$$$ ($$$1 \leq n, m \leq 10^9$$$, $$$1 \leq k \leq 10^9$$$, $$$1 \leq r \leq \min(10^6, n)$$$, $$$1 \leq c \leq \min(10^6, m)$$$) — the size of the batik, the number of colors, and size of the sub-rectangle. The second line contains four integers $$$a_x$$$, $$$a_y$$$, $$$b_x$$$, and $$$b_y$$$ ($$$1 \leq a_x, b_x \leq n$$$, $$$1 \leq a_y, b_y \leq m$$$) — the top-left corners of the first and second sub-rectangle. Both of the sub-rectangles given are inside the grid ($$$1 \leq a_x + r - 1$$$, $$$b_x + r - 1 \leq n$$$, $$$1 \leq a_y + c - 1$$$, $$$b_y + c - 1 \leq m$$$).

Output an integer denoting the number of possible batik color combinations modulo $$$10^9 + 7$$$.

NoteThe following are all $$$32$$$ possible color combinations in the first example.


The Winter holiday will be here soon. Mr. Chanek wants to decorate his house's wall with ornaments. The wall can be represented as a binary string $$$a$$$ of length $$$n$$$. His favorite nephew has another binary string $$$b$$$ of length $$$m$$$ ($$$m \leq n$$$).Mr. Chanek's nephew loves the non-negative integer $$$k$$$. His nephew wants exactly $$$k$$$ occurrences of $$$b$$$ as substrings in $$$a$$$. However, Mr. Chanek does not know the value of $$$k$$$. So, for each $$$k$$$ ($$$0 \leq k \leq n - m + 1$$$), find the minimum number of elements in $$$a$$$ that have to be changed such that there are exactly $$$k$$$ occurrences of $$$b$$$ in $$$a$$$.A string $$$s$$$ occurs exactly $$$k$$$ times in $$$t$$$ if there are exactly $$$k$$$ different pairs $$$(p,q)$$$ such that we can obtain $$$s$$$ by deleting $$$p$$$ characters from the beginning and $$$q$$$ characters from the end of $$$t$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq m \leq n \leq 500$$$) — size of the binary string $$$a$$$ and $$$b$$$ respectively. The second line contains a binary string $$$a$$$ of length $$$n$$$. The third line contains a binary string $$$b$$$ of length $$$m$$$.

Output $$$n - m + 2$$$ integers — the $$$(k+1)$$$-th integer denotes the minimal number of elements in $$$a$$$ that have to be changed so there are exactly $$$k$$$ occurrences of $$$b$$$ as a substring in $$$a$$$.

NoteFor $$$k = 0$$$, to make the string $$$a$$$ have no occurrence of 101, you can do one character change as follows.100101011 $$$\rightarrow$$$ 100100011For $$$k = 1$$$, you can also change a single character.100101011 $$$\rightarrow$$$ 100001011For $$$k = 2$$$, no changes are needed.


Mr. Chanek gives you a sequence $$$a$$$ indexed from $$$1$$$ to $$$n$$$. Define $$$f(a)$$$ as the number of indices where $$$a_i = i$$$. You can pick an element from the current sequence and remove it, then concatenate the remaining elements together. For example, if you remove the $$$3$$$-rd element from the sequence $$$[4, 2, 3, 1]$$$, the resulting sequence will be $$$[4, 2, 1]$$$. You want to remove some elements from $$$a$$$ in order to maximize $$$f(a)$$$, using zero or more operations. Find the largest possible $$$f(a)$$$.

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the initial length of the sequence. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 2 \cdot 10^5$$$) — the initial sequence $$$a$$$.

Output an integer denoting the largest $$$f(a)$$$ that can be obtained by doing zero or more operations.

NoteIn the first example, $$$f(A) = 3$$$ by doing the following operations.$$$[2,1,\textbf{4},2,5,3,7] \rightarrow [\textbf{2},1,2,5,3,7] \rightarrow [1,2,5,3,\textbf{7}] \rightarrow [1,2,\textbf{5},3] \rightarrow [1,2,3]$$$In the second example, $$$f(A) = 2$$$ and no additional operation is needed.


Mr. Chanek's city can be represented as a plane. He wants to build a housing complex in the city.There are some telephone poles on the plane, which is represented by a grid $$$a$$$ of size $$$(n + 1) \times (m + 1)$$$. There is a telephone pole at $$$(x, y)$$$ if $$$a_{x, y} = 1$$$.For each point $$$(x, y)$$$, define $$$S(x, y)$$$ as the square of the Euclidean distance between the nearest pole and $$$(x, y)$$$. Formally, the square of the Euclidean distance between two points $$$(x_1, y_1)$$$ and $$$(x_2, y_2)$$$ is $$$(x_2 - x_1)^2 + (y_2 - y_1)^2$$$.To optimize the building plan, the project supervisor asks you the sum of all $$$S(x, y)$$$ for each $$$0 \leq x \leq n$$$ and $$$0 \leq y \leq m$$$. Help him by finding the value of $$$\sum_{x=0}^{n} {\sum_{y=0}^{m} {S(x, y)}}$$$.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$0 \leq n, m < 2000$$$) — the size of the grid. Then $$$(n + 1)$$$ lines follow, each containing $$$(m + 1)$$$ integers $$$a_{i, j}$$$ ($$$0 \leq a_{i, j} \leq 1$$$) — the grid denoting the positions of telephone poles in the plane. There is at least one telephone pole in the given grid.

Output an integer denoting the value of $$$\sum_{x=0}^{n} {\sum_{y=0}^{m} {S(x, y)}}$$$.


The new generation external memory contains an array of integers $$$a[1 \ldots n] = [a_1, a_2, \ldots, a_n]$$$.This type of memory does not support changing the value of an arbitrary element. Instead, it allows you to cut out any segment of the given array, cyclically shift (rotate) it by any offset and insert it back into the same place.Technically, each cyclic shift consists of two consecutive actions:   You may select arbitrary indices $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) as the boundaries of the segment.  Then you replace the segment $$$a[l \ldots r]$$$ with it's cyclic shift to the left by an arbitrary offset $$$d$$$. The concept of a cyclic shift can be also explained by following relations: the sequence $$$[1, 4, 1, 3]$$$ is a cyclic shift of the sequence $$$[3, 1, 4, 1]$$$ to the left by the offset $$$1$$$ and the sequence $$$[4, 1, 3, 1]$$$ is a cyclic shift of the sequence $$$[3, 1, 4, 1]$$$ to the left by the offset $$$2$$$. For example, if $$$a = [1, \color{blue}{3, 2, 8}, 5]$$$, then choosing $$$l = 2$$$, $$$r = 4$$$ and $$$d = 2$$$ yields a segment $$$a[2 \ldots 4] = [3, 2, 8]$$$. This segment is then shifted by the offset $$$d = 2$$$ to the left, and you get a segment $$$[8, 3, 2]$$$ which then takes the place of of the original elements of the segment. In the end you get $$$a = [1, \color{blue}{8, 3, 2}, 5]$$$.Sort the given array $$$a$$$ using no more than $$$n$$$ cyclic shifts of any of its segments. Note that you don't need to minimize the number of cyclic shifts. Any method that requires $$$n$$$ or less cyclic shifts will be accepted.

The first line contains an integer $$$t$$$ ($$$1 \leq t \leq 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain the descriptions of the test cases.  The first line of each test case description contains an integer $$$n$$$ ($$$2 \leq n \leq 50$$$) — the length of the array. The second line consists of space-separated elements of the array $$$a_i$$$ ($$$-10^9 \leq a_i \leq 10^9$$$). Elements of array $$$a$$$ may repeat and don't have to be unique.

Print $$$t$$$ answers to all input test cases.  The first line of the answer of each test case should contain an integer $$$k$$$ ($$$0 \le k \le n$$$) — the number of actions to sort the array. The next $$$k$$$ lines should contain descriptions of the actions formatted as "$$$l$$$ $$$r$$$ $$$d$$$" (without quotes) where $$$l$$$ and $$$r$$$ ($$$1 \le l < r \le n$$$) are the boundaries of the segment being shifted, while $$$d$$$ ($$$1 \le d \le r - l$$$) is the offset value. Please remember that only the cyclic shifts to the left are considered so the chosen segment will be shifted by the offset $$$d$$$ to the to the left. Note that you are not required to find the minimum number of cyclic shifts needed for sorting. Any sorting method where the number of shifts does not exceed $$$n$$$ will be accepted. If the given array $$$a$$$ is already sorted, one of the possible answers is $$$k = 0$$$ and an empty sequence of cyclic shifts. If there are several possible answers, you may print any of them.

NoteExplanation of the fourth data set in the example:   The segment $$$a[2 \ldots 4]$$$ is selected and is shifted to the left by $$$2$$$: $$$[2, \color{blue}{5, 1, 4}, 3] \longrightarrow [2, \color{blue}{4, 5, 1}, 3]$$$  The segment $$$a[1 \ldots 5]$$$ is then selected and is shifted to the left by $$$3$$$: $$$[\color{blue}{2, 4, 5, 1, 3}] \longrightarrow [\color{blue}{1, 3, 2, 4, 5}]$$$  After that the segment $$$a[1 \ldots 2]$$$ is selected and is shifted to the left by $$$1$$$: $$$[\color{blue}{1, 3}, 2, 4, 5] \longrightarrow [\color{blue}{3, 1}, 2, 4, 5]$$$  And in the end the segment $$$a[1 \ldots 3]$$$ is selected and is shifted to the left by $$$1$$$: $$$[\color{blue}{3, 1, 2}, 4, 5] \longrightarrow [\color{blue}{1, 2, 3}, 4, 5]$$$


Casimir has a string $$$s$$$ which consists of capital Latin letters 'A', 'B', and 'C' only. Each turn he can choose to do one of the two following actions:  he can either erase exactly one letter 'A' and exactly one letter 'B' from arbitrary places of the string (these letters don't have to be adjacent);  or he can erase exactly one letter 'B' and exactly one letter 'C' from arbitrary places in the string (these letters don't have to be adjacent). Therefore, each turn the length of the string is decreased exactly by $$$2$$$. All turns are independent so for each turn, Casimir can choose any of two possible actions.For example, with $$$s$$$ $$$=$$$ "ABCABC" he can obtain a string $$$s$$$ $$$=$$$ "ACBC" in one turn (by erasing the first occurrence of 'B' and the second occurrence of 'A'). There are also many other options for a turn aside from this particular example.For a given string $$$s$$$ determine whether there is a sequence of actions leading to an empty string. In other words, Casimir's goal is to erase all letters from the string. Is there a way to do this?

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Each test case is described by one string $$$s$$$, for which you need to determine if it can be fully erased by some sequence of turns. The string $$$s$$$ consists of capital letters 'A', 'B', 'C' and has a length from $$$1$$$ to $$$50$$$ letters, inclusive.

Print $$$t$$$ lines, each line containing the answer to the corresponding test case. The answer to a test case should be YES if there is a way to fully erase the corresponding string and NO otherwise. You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes, and YES will all be recognized as positive answers).

6
ABACAB
ABBA
AC
ABC
CABCBB
BCBCBCBCBCBCBCBC


An important meeting is to be held and there are exactly $$$n$$$ people invited. At any moment, any two people can step back and talk in private. The same two people can talk several (as many as they want) times per meeting.Each person has limited sociability. The sociability of the $$$i$$$-th person is a non-negative integer $$$a_i$$$. This means that after exactly $$$a_i$$$ talks this person leaves the meeting (and does not talk to anyone else anymore). If $$$a_i = 0$$$, the $$$i$$$-th person leaves the meeting immediately after it starts.A meeting is considered most productive if the maximum possible number of talks took place during it.You are given an array of sociability $$$a$$$, determine which people should talk to each other so that the total number of talks is as large as possible.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The next $$$2t$$$ lines contain descriptions of the test cases. The first line of each test case description contains an integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) —the number of people in the meeting. The second line consists of $$$n$$$ space-separated integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 2 \cdot 10^5$$$) — the sociability parameters of all people.  It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$. It is also guaranteed that the sum of all $$$a_i$$$ (over all test cases and all $$$i$$$) does not exceed $$$2 \cdot 10^5$$$.

Print $$$t$$$ answers to all test cases. On the first line of each answer print the number $$$k$$$ — the maximum number of talks possible in a meeting. On each of the next $$$k$$$ lines print two integers $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le n$$$ and $$$i \neq j$$$) — the numbers of people who will have another talk. If there are several possible answers, you may print any of them.