It is Professor R's last class of his teaching career. Every time Professor R taught a class, he gave a special problem for the students to solve. You being his favourite student, put your heart into solving it one last time.You are given two polynomials $$$f(x) = a_0 + a_1x + \dots + a_{n-1}x^{n-1}$$$ and $$$g(x) = b_0 + b_1x + \dots + b_{m-1}x^{m-1}$$$, with positive integral coefficients. It is guaranteed that the cumulative GCD of the coefficients is equal to $$$1$$$ for both the given polynomials. In other words, $$$gcd(a_0, a_1, \dots, a_{n-1}) = gcd(b_0, b_1, \dots, b_{m-1}) = 1$$$. Let $$$h(x) = f(x)\cdot g(x)$$$. Suppose that $$$h(x) = c_0 + c_1x + \dots + c_{n+m-2}x^{n+m-2}$$$. You are also given a prime number $$$p$$$. Professor R challenges you to find any $$$t$$$ such that $$$c_t$$$ isn't divisible by $$$p$$$. He guarantees you that under these conditions such $$$t$$$ always exists. If there are several such $$$t$$$, output any of them.As the input is quite large, please use fast input reading methods.

The first line of the input contains three integers, $$$n$$$, $$$m$$$ and $$$p$$$ ($$$1 \leq n, m \leq 10^6, 2 \leq p \leq 10^9$$$),  — $$$n$$$ and $$$m$$$ are the number of terms in $$$f(x)$$$ and $$$g(x)$$$ respectively (one more than the degrees of the respective polynomials) and $$$p$$$ is the given prime number. It is guaranteed that $$$p$$$ is prime. The second line contains $$$n$$$ integers $$$a_0, a_1, \dots, a_{n-1}$$$ ($$$1 \leq a_{i} \leq 10^{9}$$$) — $$$a_i$$$ is the coefficient of $$$x^{i}$$$ in $$$f(x)$$$. The third line contains $$$m$$$ integers $$$b_0, b_1, \dots, b_{m-1}$$$ ($$$1 \leq b_{i} \leq 10^{9}$$$)  — $$$b_i$$$ is the coefficient of $$$x^{i}$$$ in $$$g(x)$$$.

Print a single integer $$$t$$$ ($$$0\le t \le n+m-2$$$)  — the appropriate power of $$$x$$$ in $$$h(x)$$$ whose coefficient isn't divisible by the given prime $$$p$$$. If there are multiple powers of $$$x$$$ that satisfy the condition, print any.

NoteIn the first test case, $$$f(x)$$$ is $$$2x^2 + x + 1$$$ and $$$g(x)$$$ is $$$x + 2$$$, their product $$$h(x)$$$ being $$$2x^3 + 5x^2 + 3x + 2$$$, so the answer can be 1 or 2 as both 3 and 5 aren't divisible by 2.In the second test case, $$$f(x)$$$ is $$$x + 2$$$ and $$$g(x)$$$ is $$$x + 3$$$, their product $$$h(x)$$$ being $$$x^2 + 5x + 6$$$, so the answer can be any of the powers as no coefficient is divisible by the given prime.


Nash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands. This board game is played on the $$$n\times n$$$ board. Rows and columns of this board are numbered from $$$1$$$ to $$$n$$$. The cell on the intersection of the $$$r$$$-th row and $$$c$$$-th column is denoted by $$$(r, c)$$$.Some cells on the board are called blocked zones. On each cell of the board, there is written one of the following $$$5$$$ characters  — $$$U$$$, $$$D$$$, $$$L$$$, $$$R$$$ or $$$X$$$  — instructions for the player. Suppose that the current cell is $$$(r, c)$$$. If the character is $$$R$$$, the player should move to the right cell $$$(r, c+1)$$$, for $$$L$$$ the player should move to the left cell $$$(r, c-1)$$$, for $$$U$$$ the player should move to the top cell $$$(r-1, c)$$$, for $$$D$$$ the player should move to the bottom cell $$$(r+1, c)$$$. Finally, if the character in the cell is $$$X$$$, then this cell is the blocked zone. The player should remain in this cell (the game for him isn't very interesting from now on).It is guaranteed that the characters are written in a way that the player will never have to step outside of the board, no matter at which cell he starts.As a player starts from a cell, he moves according to the character in the current cell. The player keeps moving until he lands in a blocked zone. It is also possible that the player will keep moving infinitely long.For every of the $$$n^2$$$ cells of the board Alice, your friend, wants to know, how will the game go, if the player starts in this cell. For each starting cell of the board, she writes down the cell that the player stops at, or that the player never stops at all. She gives you the information she has written: for each cell $$$(r, c)$$$ she wrote:   a pair ($$$x$$$,$$$y$$$), meaning if a player had started at $$$(r, c)$$$, he would end up at cell ($$$x$$$,$$$y$$$).  or a pair ($$$-1$$$,$$$-1$$$), meaning if a player had started at $$$(r, c)$$$, he would keep moving infinitely long and would never enter the blocked zone. It might be possible that Alice is trying to fool you and there's no possible grid that satisfies all the constraints Alice gave you. For the given information Alice provided you, you are required to decipher a possible board, or to determine that such a board doesn't exist. If there exist several different boards that satisfy the provided information, you can find any of them.

The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 10^{3}$$$)  — the side of the board. The $$$i$$$-th of the next $$$n$$$ lines of the input contains $$$2n$$$ integers $$$x_1, y_1, x_2, y_2, \dots, x_n, y_n$$$, where $$$(x_j, y_j)$$$ ($$$1 \leq x_j \leq n, 1 \leq y_j \leq n$$$, or $$$(x_j,y_j)=(-1,-1)$$$) is the pair written by Alice for the cell $$$(i, j)$$$.

If there doesn't exist a board satisfying the information that Alice gave you, print a single line containing INVALID.  Otherwise, in the first line print VALID. In the $$$i$$$-th of the next $$$n$$$ lines, print the string of $$$n$$$ characters, corresponding to the characters in the $$$i$$$-th row of the suitable board you found. Each character of a string can either be $$$U$$$, $$$D$$$, $$$L$$$, $$$R$$$ or $$$X$$$. If there exist several different boards that satisfy the provided information, you can find any of them.

NoteFor the sample test 1 :The given grid in output is a valid one.   If the player starts at $$$(1,1)$$$, he doesn't move any further following $$$X$$$ and stops there.  If the player starts at $$$(1,2)$$$, he moves to left following $$$L$$$ and stops at $$$(1,1)$$$.  If the player starts at $$$(2,1)$$$, he moves to right following $$$R$$$ and stops at $$$(2,2)$$$.  If the player starts at $$$(2,2)$$$, he doesn't move any further following $$$X$$$ and stops there. The simulation can be seen below :   For the sample test 2 : The given grid in output is a valid one, as a player starting at any cell other than the one at center $$$(2,2)$$$, keeps moving in an infinitely long cycle and never stops. Had he started at $$$(2,2)$$$, he wouldn't have moved further following instruction $$$X$$$ .The simulation can be seen below :


Alice, the president of club FCB, wants to build a team for the new volleyball tournament. The team should consist of $$$p$$$ players playing in $$$p$$$ different positions. She also recognizes the importance of audience support, so she wants to select $$$k$$$ people as part of the audience.There are $$$n$$$ people in Byteland. Alice needs to select exactly $$$p$$$ players, one for each position, and exactly $$$k$$$ members of the audience from this pool of $$$n$$$ people. Her ultimate goal is to maximize the total strength of the club.The $$$i$$$-th of the $$$n$$$ persons has an integer $$$a_{i}$$$ associated with him — the strength he adds to the club if he is selected as a member of the audience.For each person $$$i$$$ and for each position $$$j$$$, Alice knows $$$s_{i, j}$$$  — the strength added by the $$$i$$$-th person to the club if he is selected to play in the $$$j$$$-th position.Each person can be selected at most once as a player or a member of the audience. You have to choose exactly one player for each position.Since Alice is busy, she needs you to help her find the maximum possible strength of the club that can be achieved by an optimal choice of players and the audience.

The first line contains $$$3$$$ integers $$$n,p,k$$$ ($$$2 \leq n \leq 10^{5}, 1 \leq p \leq 7, 1 \le k, p+k \le n$$$). The second line contains $$$n$$$ integers $$$a_{1},a_{2},\ldots,a_{n}$$$. ($$$1 \leq a_{i} \leq 10^{9}$$$). The $$$i$$$-th of the next $$$n$$$ lines contains $$$p$$$ integers $$$s_{i, 1}, s_{i, 2}, \dots, s_{i, p}$$$. ($$$1 \leq s_{i,j} \leq 10^{9}$$$)

Print a single integer $$${res}$$$  — the maximum possible strength of the club.

NoteIn the first sample, we can select person $$$1$$$ to play in the $$$1$$$-st position and persons $$$2$$$ and $$$3$$$ as audience members. Then the total strength of the club will be equal to $$$a_{2}+a_{3}+s_{1,1}$$$.


Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be $$$n$$$ participants, one of whom is Nikolay. Like any good olympiad, it consists of two rounds. Tired of the traditional rules, in which the participant who solved the largest number of problems wins, the organizers came up with different rules.Suppose in the first round participant A took $$$x$$$-th place and in the second round — $$$y$$$-th place. Then the total score of the participant A is sum $$$x + y$$$. The overall place of the participant A is the number of participants (including A) having their total score less than or equal to the total score of A. Note, that some participants may end up having a common overall place. It is also important to note, that in both the first and the second round there were no two participants tying at a common place. In other words, for every $$$i$$$ from $$$1$$$ to $$$n$$$ exactly one participant took $$$i$$$-th place in first round and exactly one participant took $$$i$$$-th place in second round.Right after the end of the Olympiad, Nikolay was informed that he got $$$x$$$-th place in first round and $$$y$$$-th place in the second round. Nikolay doesn't know the results of other participants, yet he wonders what is the minimum and maximum place he can take, if we consider the most favorable and unfavorable outcome for him. Please help Nikolay to find the answer to this question.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases to solve. Each of the following $$$t$$$ lines contains integers $$$n$$$, $$$x$$$, $$$y$$$ ($$$1 \leq n \leq 10^9$$$, $$$1 \le x, y \le n$$$) — the number of participants in the olympiad, the place that Nikolay took in the first round and the place that Nikolay took in the second round.

Print two integers — the minimum and maximum possible overall place Nikolay could take.

NoteExplanation for the first example:Suppose there were 5 participants A-E. Let's denote Nikolay as A. The the most favorable results for Nikolay could look as follows:  However, the results of the Olympiad could also look like this:  In the first case Nikolay would have taken first place, and in the second — third place.


There are $$$n$$$ officers in the Army of Byteland. Each officer has some power associated with him. The power of the $$$i$$$-th officer is denoted by $$$p_{i}$$$. As the war is fast approaching, the General would like to know the strength of the army.The strength of an army is calculated in a strange way in Byteland. The General selects a random subset of officers from these $$$n$$$ officers and calls this subset a battalion.(All $$$2^n$$$ subsets of the $$$n$$$ officers can be chosen equally likely, including empty subset and the subset of all officers).The strength of a battalion is calculated in the following way:Let the powers of the chosen officers be $$$a_{1},a_{2},\ldots,a_{k}$$$, where $$$a_1 \le a_2 \le \dots \le a_k$$$. The strength of this battalion is equal to $$$a_1a_2 + a_2a_3 + \dots + a_{k-1}a_k$$$. (If the size of Battalion is $$$\leq 1$$$, then the strength of this battalion is $$$0$$$).The strength of the army is equal to the expected value of the strength of the battalion.As the war is really long, the powers of officers may change. Precisely, there will be $$$q$$$ changes. Each one of the form $$$i$$$ $$$x$$$ indicating that $$$p_{i}$$$ is changed to $$$x$$$.You need to find the strength of the army initially and after each of these $$$q$$$ updates.Note that the changes are permanent.The strength should be found by modulo $$$10^{9}+7$$$. Formally, let $$$M=10^{9}+7$$$. It can be shown that the answer can be expressed as an irreducible fraction $$$p/q$$$, where $$$p$$$ and $$$q$$$ are integers and $$$q\not\equiv 0 \bmod M$$$). Output the integer equal to $$$p\cdot q^{-1} \bmod M$$$. In other words, output such an integer $$$x$$$ that $$$0 \leq x < M$$$ and $$$x ⋅ q \equiv p \bmod M$$$).

The first line of the input contains a single integer $$$n$$$ ($$$1 \leq n \leq 3⋅10^{5}$$$)  — the number of officers in Byteland's Army. The second line contains $$$n$$$ integers $$$p_{1},p_{2},\ldots,p_{n}$$$ ($$$1 \leq p_{i} \leq 10^{9}$$$). The third line contains a single integer $$$q$$$ ($$$1 \leq q \leq 3⋅10^{5}$$$)  — the number of updates. Each of the next $$$q$$$ lines contains two integers $$$i$$$ and $$$x$$$ ($$$1 \leq i \leq n$$$, $$$ 1 \leq x \leq 10^{9}$$$), indicating that $$$p_{i}$$$ is updated to $$$x$$$ .

In the first line output the initial strength of the army. In $$$i$$$-th of the next $$$q$$$ lines, output the strength of the army after $$$i$$$-th update.

NoteIn first testcase, initially, there are four possible battalions   {} Strength = $$$0$$$  {$$$1$$$} Strength = $$$0$$$  {$$$2$$$} Strength = $$$0$$$  {$$$1,2$$$} Strength = $$$2$$$  So strength of army is $$$\frac{0+0+0+2}{4}$$$ = $$$\frac{1}{2}$$$After changing $$$p_{1}$$$ to $$$2$$$, strength of battallion {$$$1,2$$$} changes to $$$4$$$, so strength of army becomes $$$1$$$.After changing $$$p_{2}$$$ to $$$1$$$, strength of battalion {$$$1,2$$$} again becomes $$$2$$$, so strength of army becomes $$$\frac{1}{2}$$$.


Tanya wants to go on a journey across the cities of Berland. There are $$$n$$$ cities situated along the main railroad line of Berland, and these cities are numbered from $$$1$$$ to $$$n$$$. Tanya plans her journey as follows. First of all, she will choose some city $$$c_1$$$ to start her journey. She will visit it, and after that go to some other city $$$c_2 > c_1$$$, then to some other city $$$c_3 > c_2$$$, and so on, until she chooses to end her journey in some city $$$c_k > c_{k - 1}$$$. So, the sequence of visited cities $$$[c_1, c_2, \dots, c_k]$$$ should be strictly increasing.There are some additional constraints on the sequence of cities Tanya visits. Each city $$$i$$$ has a beauty value $$$b_i$$$ associated with it. If there is only one city in Tanya's journey, these beauty values imply no additional constraints. But if there are multiple cities in the sequence, then for any pair of adjacent cities $$$c_i$$$ and $$$c_{i + 1}$$$, the condition $$$c_{i + 1} - c_i = b_{c_{i + 1}} - b_{c_i}$$$ must hold.For example, if $$$n = 8$$$ and $$$b = [3, 4, 4, 6, 6, 7, 8, 9]$$$, there are several three possible ways to plan a journey:  $$$c = [1, 2, 4]$$$;  $$$c = [3, 5, 6, 8]$$$;  $$$c = [7]$$$ (a journey consisting of one city is also valid). There are some additional ways to plan a journey that are not listed above.Tanya wants her journey to be as beautiful as possible. The beauty value of the whole journey is the sum of beauty values over all visited cities. Can you help her to choose the optimal plan, that is, to maximize the beauty value of the journey?

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the number of cities in Berland. The second line contains $$$n$$$ integers $$$b_1$$$, $$$b_2$$$, ..., $$$b_n$$$ ($$$1 \le b_i \le 4 \cdot 10^5$$$), where $$$b_i$$$ is the beauty value of the $$$i$$$-th city.

Print one integer — the maximum beauty of a journey Tanya can choose.

NoteThe optimal journey plan in the first example is $$$c = [2, 4, 5]$$$.The optimal journey plan in the second example is $$$c = [1]$$$.The optimal journey plan in the third example is $$$c = [3, 6]$$$.


The map of Bertown can be represented as a set of $$$n$$$ intersections, numbered from $$$1$$$ to $$$n$$$ and connected by $$$m$$$ one-way roads. It is possible to move along the roads from any intersection to any other intersection. The length of some path from one intersection to another is the number of roads that one has to traverse along the path. The shortest path from one intersection $$$v$$$ to another intersection $$$u$$$ is the path that starts in $$$v$$$, ends in $$$u$$$ and has the minimum length among all such paths.Polycarp lives near the intersection $$$s$$$ and works in a building near the intersection $$$t$$$. Every day he gets from $$$s$$$ to $$$t$$$ by car. Today he has chosen the following path to his workplace: $$$p_1$$$, $$$p_2$$$, ..., $$$p_k$$$, where $$$p_1 = s$$$, $$$p_k = t$$$, and all other elements of this sequence are the intermediate intersections, listed in the order Polycarp arrived at them. Polycarp never arrived at the same intersection twice, so all elements of this sequence are pairwise distinct. Note that you know Polycarp's path beforehand (it is fixed), and it is not necessarily one of the shortest paths from $$$s$$$ to $$$t$$$.Polycarp's car has a complex navigation system installed in it. Let's describe how it works. When Polycarp starts his journey at the intersection $$$s$$$, the system chooses some shortest path from $$$s$$$ to $$$t$$$ and shows it to Polycarp. Let's denote the next intersection in the chosen path as $$$v$$$. If Polycarp chooses to drive along the road from $$$s$$$ to $$$v$$$, then the navigator shows him the same shortest path (obviously, starting from $$$v$$$ as soon as he arrives at this intersection). However, if Polycarp chooses to drive to another intersection $$$w$$$ instead, the navigator rebuilds the path: as soon as Polycarp arrives at $$$w$$$, the navigation system chooses some shortest path from $$$w$$$ to $$$t$$$ and shows it to Polycarp. The same process continues until Polycarp arrives at $$$t$$$: if Polycarp moves along the road recommended by the system, it maintains the shortest path it has already built; but if Polycarp chooses some other path, the system rebuilds the path by the same rules.Here is an example. Suppose the map of Bertown looks as follows, and Polycarp drives along the path $$$[1, 2, 3, 4]$$$ ($$$s = 1$$$, $$$t = 4$$$): Check the picture by the link http://tk.codeforces.com/a.png   When Polycarp starts at $$$1$$$, the system chooses some shortest path from $$$1$$$ to $$$4$$$. There is only one such path, it is $$$[1, 5, 4]$$$;  Polycarp chooses to drive to $$$2$$$, which is not along the path chosen by the system. When Polycarp arrives at $$$2$$$, the navigator rebuilds the path by choosing some shortest path from $$$2$$$ to $$$4$$$, for example, $$$[2, 6, 4]$$$ (note that it could choose $$$[2, 3, 4]$$$);  Polycarp chooses to drive to $$$3$$$, which is not along the path chosen by the system. When Polycarp arrives at $$$3$$$, the navigator rebuilds the path by choosing the only shortest path from $$$3$$$ to $$$4$$$, which is $$$[3, 4]$$$;  Polycarp arrives at $$$4$$$ along the road chosen by the navigator, so the system does not have to rebuild anything. Overall, we get $$$2$$$ rebuilds in this scenario. Note that if the system chose $$$[2, 3, 4]$$$ instead of $$$[2, 6, 4]$$$ during the second step, there would be only $$$1$$$ rebuild (since Polycarp goes along the path, so the system maintains the path $$$[3, 4]$$$ during the third step).The example shows us that the number of rebuilds can differ even if the map of Bertown and the path chosen by Polycarp stays the same. Given this information (the map and Polycarp's path), can you determine the minimum and the maximum number of rebuilds that could have happened during the journey?

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$2 \le n \le m \le 2 \cdot 10^5$$$) — the number of intersections and one-way roads in Bertown, respectively. Then $$$m$$$ lines follow, each describing a road. Each line contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le n$$$, $$$u \ne v$$$) denoting a road from intersection $$$u$$$ to intersection $$$v$$$. All roads in Bertown are pairwise distinct, which means that each ordered pair $$$(u, v)$$$ appears at most once in these $$$m$$$ lines (but if there is a road $$$(u, v)$$$, the road $$$(v, u)$$$ can also appear). The following line contains one integer $$$k$$$ ($$$2 \le k \le n$$$) — the number of intersections in Polycarp's path from home to his workplace. The last line contains $$$k$$$ integers $$$p_1$$$, $$$p_2$$$, ..., $$$p_k$$$ ($$$1 \le p_i \le n$$$, all these integers are pairwise distinct) — the intersections along Polycarp's path in the order he arrived at them. $$$p_1$$$ is the intersection where Polycarp lives ($$$s = p_1$$$), and $$$p_k$$$ is the intersection where Polycarp's workplace is situated ($$$t = p_k$$$). It is guaranteed that for every $$$i \in [1, k - 1]$$$ the road from $$$p_i$$$ to $$$p_{i + 1}$$$ exists, so the path goes along the roads of Bertown.

Print two integers: the minimum and the maximum number of rebuilds that could have happened during the journey.


$$$n$$$ students are taking an exam. The highest possible score at this exam is $$$m$$$. Let $$$a_{i}$$$ be the score of the $$$i$$$-th student. You have access to the school database which stores the results of all students.You can change each student's score as long as the following conditions are satisfied:   All scores are integers  $$$0 \leq a_{i} \leq m$$$  The average score of the class doesn't change. You are student $$$1$$$ and you would like to maximize your own score.Find the highest possible score you can assign to yourself such that all conditions are satisfied.

Each test contains multiple test cases.  The first line contains the number of test cases $$$t$$$ ($$$1 \le t \le 200$$$). The description of the test cases follows. The first line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$1 \leq n \leq 10^{3}$$$, $$$1 \leq m \leq 10^{5}$$$)  — the number of students and the highest possible score respectively. The second line of each testcase contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$ 0 \leq a_{i} \leq m$$$)  — scores of the students.

For each testcase, output one integer  — the highest possible score you can assign to yourself such that both conditions are satisfied._

NoteIn the first case, $$$a = [1,2,3,4] $$$, with average of $$$2.5$$$. You can change array $$$a$$$ to $$$[10,0,0,0]$$$. Average remains $$$2.5$$$, and all conditions are satisfied.In the second case, $$$0 \leq a_{i} \leq 5$$$. You can change $$$a$$$ to $$$[5,1,1,3]$$$. You cannot increase $$$a_{1}$$$ further as it will violate condition $$$0\le a_i\le m$$$.


Roma is playing a new expansion for his favorite game World of Darkraft. He made a new character and is going for his first grind.Roma has a choice to buy exactly one of $$$n$$$ different weapons and exactly one of $$$m$$$ different armor sets. Weapon $$$i$$$ has attack modifier $$$a_i$$$ and is worth $$$ca_i$$$ coins, and armor set $$$j$$$ has defense modifier $$$b_j$$$ and is worth $$$cb_j$$$ coins.After choosing his equipment Roma can proceed to defeat some monsters. There are $$$p$$$ monsters he can try to defeat. Monster $$$k$$$ has defense $$$x_k$$$, attack $$$y_k$$$ and possesses $$$z_k$$$ coins. Roma can defeat a monster if his weapon's attack modifier is larger than the monster's defense, and his armor set's defense modifier is larger than the monster's attack. That is, a monster $$$k$$$ can be defeated with a weapon $$$i$$$ and an armor set $$$j$$$ if $$$a_i > x_k$$$ and $$$b_j > y_k$$$. After defeating the monster, Roma takes all the coins from them. During the grind, Roma can defeat as many monsters as he likes. Monsters do not respawn, thus each monster can be defeated at most one.Thanks to Roma's excessive donations, we can assume that he has an infinite amount of in-game currency and can afford any of the weapons and armor sets. Still, he wants to maximize the profit of the grind. The profit is defined as the total coins obtained from all defeated monsters minus the cost of his equipment. Note that Roma must purchase a weapon and an armor set even if he can not cover their cost with obtained coins.Help Roma find the maximum profit of the grind.

The first line contains three integers $$$n$$$, $$$m$$$, and $$$p$$$ ($$$1 \leq n, m, p \leq 2 \cdot 10^5$$$) — the number of available weapons, armor sets and monsters respectively. The following $$$n$$$ lines describe available weapons. The $$$i$$$-th of these lines contains two integers $$$a_i$$$ and $$$ca_i$$$ ($$$1 \leq a_i \leq 10^6$$$, $$$1 \leq ca_i \leq 10^9$$$) — the attack modifier and the cost of the weapon $$$i$$$. The following $$$m$$$ lines describe available armor sets. The $$$j$$$-th of these lines contains two integers $$$b_j$$$ and $$$cb_j$$$ ($$$1 \leq b_j \leq 10^6$$$, $$$1 \leq cb_j \leq 10^9$$$) — the defense modifier and the cost of the armor set $$$j$$$. The following $$$p$$$ lines describe monsters. The $$$k$$$-th of these lines contains three integers $$$x_k, y_k, z_k$$$ ($$$1 \leq x_k, y_k \leq 10^6$$$, $$$1 \leq z_k \leq 10^3$$$) — defense, attack and the number of coins of the monster $$$k$$$.

Print a single integer — the maximum profit of the grind.


There are $$$n$$$ cities in Treeland connected with $$$n - 1$$$ bidirectional roads in such that a way that any city is reachable from any other; in other words, the graph of cities and roads is a tree. Treeland is preparing for a seasonal virus epidemic, and currently, they are trying to evaluate different infection scenarios.In each scenario, several cities are initially infected with different virus species. Suppose that there are $$$k_i$$$ virus species in the $$$i$$$-th scenario. Let us denote $$$v_j$$$ the initial city for the virus $$$j$$$, and $$$s_j$$$ the propagation speed of the virus $$$j$$$. The spread of the viruses happens in turns: first virus $$$1$$$ spreads, followed by virus $$$2$$$, and so on. After virus $$$k_i$$$ spreads, the process starts again from virus $$$1$$$.A spread turn of virus $$$j$$$ proceeds as follows. For each city $$$x$$$ not infected with any virus at the start of the turn, at the end of the turn it becomes infected with virus $$$j$$$ if and only if there is such a city $$$y$$$ that: city $$$y$$$ was infected with virus $$$j$$$ at the start of the turn; the path between cities $$$x$$$ and $$$y$$$ contains at most $$$s_j$$$ edges; all cities on the path between cities $$$x$$$ and $$$y$$$ (excluding $$$y$$$) were uninfected with any virus at the start of the turn.Once a city is infected with a virus, it stays infected indefinitely and can not be infected with any other virus. The spread stops once all cities are infected.You need to process $$$q$$$ independent scenarios. Each scenario is described by $$$k_i$$$ virus species and $$$m_i$$$ important cities. For each important city determine which the virus it will be infected by in the end.

The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 2 \cdot 10^5$$$) — the number of cities in Treeland. The following $$$n - 1$$$ lines describe the roads. The $$$i$$$-th of these lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$1 \leq x_i, y_i \leq n$$$) — indices of cities connecting by the $$$i$$$-th road. It is guaranteed that the given graph of cities and roads is a tree. The next line contains a single integer $$$q$$$ ($$$1 \leq q \leq 2 \cdot 10^5$$$) — the number of infection scenarios. $$$q$$$ scenario descriptions follow. The description of the $$$i$$$-th scenario starts with a line containing two integers $$$k_i$$$ and $$$m_i$$$ ($$$1 \leq k_i, m_i \leq n$$$) — the number of virus species and the number of important cities in this scenario respectively. It is guaranteed that $$$\sum_{i = 1}^ q k_i$$$ and $$$\sum_{i = 1}^ q m_i$$$ do not exceed $$$2 \cdot 10^5$$$. The following $$$k_i$$$ lines describe the virus species. The $$$j$$$-th of these lines contains two integers $$$v_j$$$ and $$$s_j$$$ ($$$1 \leq v_j \leq n$$$, $$$1 \leq s_j \leq 10^6$$$) – the initial city and the propagation speed of the virus species $$$j$$$. It is guaranteed that the initial cities of all virus species within a scenario are distinct. The following line contains $$$m_i$$$ distinct integers $$$u_1, \ldots, u_{m_i}$$$ ($$$1 \leq u_j \leq n$$$) — indices of important cities.

Print $$$q$$$ lines. The $$$i$$$-th line should contain $$$m_i$$$ integers — indices of virus species that cities $$$u_1, \ldots, u_{m_i}$$$ are infected with at the end of the $$$i$$$-th scenario.


In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $$$s$$$ starting from the $$$l$$$-th character and ending with the $$$r$$$-th character as $$$s[l \dots r]$$$. The characters of each string are numbered from $$$1$$$.We can perform several operations on the strings we consider. Each operation is to choose a substring of our string and replace it with another string. There are two possible types of operations: replace 011 with 110, or replace 110 with 011. For example, if we apply exactly one operation to the string 110011110, it can be transformed into 011011110, 110110110, or 110011011.Binary string $$$a$$$ is considered reachable from binary string $$$b$$$ if there exists a sequence $$$s_1$$$, $$$s_2$$$, ..., $$$s_k$$$ such that $$$s_1 = a$$$, $$$s_k = b$$$, and for every $$$i \in [1, k - 1]$$$, $$$s_i$$$ can be transformed into $$$s_{i + 1}$$$ using exactly one operation. Note that $$$k$$$ can be equal to $$$1$$$, i. e., every string is reachable from itself.You are given a string $$$t$$$ and $$$q$$$ queries to it. Each query consists of three integers $$$l_1$$$, $$$l_2$$$ and $$$len$$$. To answer each query, you have to determine whether $$$t[l_1 \dots l_1 + len - 1]$$$ is reachable from $$$t[l_2 \dots l_2 + len - 1]$$$.

The first line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the length of string $$$t$$$. The second line contains one string $$$t$$$ ($$$|t| = n$$$). Each character of $$$t$$$ is either 0 or 1. The third line contains one integer $$$q$$$ ($$$1 \le q \le 2 \cdot 10^5$$$) — the number of queries. Then $$$q$$$ lines follow, each line represents a query. The $$$i$$$-th line contains three integers $$$l_1$$$, $$$l_2$$$ and $$$len$$$ ($$$1 \le l_1, l_2 \le |t|$$$, $$$1 \le len \le |t| - \max(l_1, l_2) + 1$$$) for the $$$i$$$-th query.

For each query, print either YES if $$$t[l_1 \dots l_1 + len - 1]$$$ is reachable from $$$t[l_2 \dots l_2 + len - 1]$$$, or NO otherwise. You may print each letter in any register.


Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realized that she couldn't compute it for a very large array, thus she asked for your help. Can you do it? Formally, you need to compute$$$$$$ (a_1 + a_2) \oplus (a_1 + a_3) \oplus \ldots \oplus (a_1 + a_n) \\ \oplus (a_2 + a_3) \oplus \ldots \oplus (a_2 + a_n) \\ \ldots \\ \oplus (a_{n-1} + a_n) \\ $$$$$$Here $$$x \oplus y$$$ is a bitwise XOR operation (i.e. $$$x$$$ ^ $$$y$$$ in many modern programming languages). You can read about it in Wikipedia: https://en.wikipedia.org/wiki/Exclusive_or#Bitwise_operation.

The first line contains a single integer $$$n$$$ ($$$2 \leq n \leq 400\,000$$$) — the number of integers in the array. The second line contains integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 10^7$$$).

Print a single integer — xor of all pairwise sums of integers in the given array.

NoteIn the first sample case there is only one sum $$$1 + 2 = 3$$$.In the second sample case there are three sums: $$$1 + 2 = 3$$$, $$$1 + 3 = 4$$$, $$$2 + 3 = 5$$$. In binary they are represented as $$$011_2 \oplus 100_2 \oplus 101_2 = 010_2$$$, thus the answer is 2.$$$\oplus$$$ is the bitwise xor operation. To define $$$x \oplus y$$$, consider binary representations of integers $$$x$$$ and $$$y$$$. We put the $$$i$$$-th bit of the result to be 1 when exactly one of the $$$i$$$-th bits of $$$x$$$ and $$$y$$$ is 1. Otherwise, the $$$i$$$-th bit of the result is put to be 0. For example, $$$0101_2 \, \oplus \, 0011_2 = 0110_2$$$.


A popular reality show is recruiting a new cast for the third season! $$$n$$$ candidates numbered from $$$1$$$ to $$$n$$$ have been interviewed. The candidate $$$i$$$ has aggressiveness level $$$l_i$$$, and recruiting this candidate will cost the show $$$s_i$$$ roubles.The show host reviewes applications of all candidates from $$$i=1$$$ to $$$i=n$$$ by increasing of their indices, and for each of them she decides whether to recruit this candidate or not. If aggressiveness level of the candidate $$$i$$$ is strictly higher than that of any already accepted candidates, then the candidate $$$i$$$ will definitely be rejected. Otherwise the host may accept or reject this candidate at her own discretion. The host wants to choose the cast so that to maximize the total profit.The show makes revenue as follows. For each aggressiveness level $$$v$$$ a corresponding profitability value $$$c_v$$$ is specified, which can be positive as well as negative. All recruited participants enter the stage one by one by increasing of their indices. When the participant $$$i$$$ enters the stage, events proceed as follows:  The show makes $$$c_{l_i}$$$ roubles, where $$$l_i$$$ is initial aggressiveness level of the participant $$$i$$$.  If there are two participants with the same aggressiveness level on stage, they immediately start a fight. The outcome of this is:  the defeated participant is hospitalized and leaves the show.  aggressiveness level of the victorious participant is increased by one, and the show makes $$$c_t$$$ roubles, where $$$t$$$ is the new aggressiveness level.  The fights continue until all participants on stage have distinct aggressiveness levels. It is allowed to select an empty set of participants (to choose neither of the candidates).The host wants to recruit the cast so that the total profit is maximized. The profit is calculated as the total revenue from the events on stage, less the total expenses to recruit all accepted participants (that is, their total $$$s_i$$$). Help the host to make the show as profitable as possible.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 2000$$$) — the number of candidates and an upper bound for initial aggressiveness levels. The second line contains $$$n$$$ integers $$$l_i$$$ ($$$1 \le l_i \le m$$$) — initial aggressiveness levels of all candidates. The third line contains $$$n$$$ integers $$$s_i$$$ ($$$0 \le s_i \le 5000$$$) — the costs (in roubles) to recruit each of the candidates. The fourth line contains $$$n + m$$$ integers $$$c_i$$$ ($$$|c_i| \le 5000$$$) — profitability for each aggrressiveness level. It is guaranteed that aggressiveness level of any participant can never exceed $$$n + m$$$ under given conditions.

Print a single integer — the largest profit of the show.

NoteIn the first sample case it is optimal to recruit candidates $$$1, 2, 3, 5$$$. Then the show will pay $$$1 + 2 + 1 + 1 = 5$$$ roubles for recruitment. The events on stage will proceed as follows:  a participant with aggressiveness level $$$4$$$ enters the stage, the show makes $$$4$$$ roubles;  a participant with aggressiveness level $$$3$$$ enters the stage, the show makes $$$3$$$ roubles;  a participant with aggressiveness level $$$1$$$ enters the stage, the show makes $$$1$$$ rouble;  a participant with aggressiveness level $$$1$$$ enters the stage, the show makes $$$1$$$ roubles, a fight starts. One of the participants leaves, the other one increases his aggressiveness level to $$$2$$$. The show will make extra $$$2$$$ roubles for this. Total revenue of the show will be $$$4 + 3 + 1 + 1 + 2=11$$$ roubles, and the profit is $$$11 - 5 = 6$$$ roubles.In the second sample case it is impossible to recruit both candidates since the second one has higher aggressiveness, thus it is better to recruit the candidate $$$1$$$.


Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.You are given a bipartite graph with positive integers in all vertices of the right half. For a subset $$$S$$$ of vertices of the left half we define $$$N(S)$$$ as the set of all vertices of the right half adjacent to at least one vertex in $$$S$$$, and $$$f(S)$$$ as the sum of all numbers in vertices of $$$N(S)$$$. Find the greatest common divisor of $$$f(S)$$$ for all possible non-empty subsets $$$S$$$ (assume that GCD of empty set is $$$0$$$).Wu is too tired after his training to solve this problem. Help him!

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 500\,000$$$) — the number of test cases in the given test set. Test case descriptions follow. The first line of each case description contains two integers $$$n$$$ and $$$m$$$ ($$$1~\leq~n,~m~\leq~500\,000$$$) — the number of vertices in either half of the graph, and the number of edges respectively. The second line contains $$$n$$$ integers $$$c_i$$$ ($$$1 \leq c_i \leq 10^{12}$$$). The $$$i$$$-th number describes the integer in the vertex $$$i$$$ of the right half of the graph. Each of the following $$$m$$$ lines contains a pair of integers $$$u_i$$$ and $$$v_i$$$ ($$$1 \leq u_i, v_i \leq n$$$), describing an edge between the vertex $$$u_i$$$ of the left half and the vertex $$$v_i$$$ of the right half. It is guaranteed that the graph does not contain multiple edges. Test case descriptions are separated with empty lines. The total value of $$$n$$$ across all test cases does not exceed $$$500\,000$$$, and the total value of $$$m$$$ across all test cases does not exceed $$$500\,000$$$ as well.

For each test case print a single integer — the required greatest common divisor.

NoteThe greatest common divisor of a set of integers is the largest integer $$$g$$$ such that all elements of the set are divisible by $$$g$$$.In the first sample case vertices of the left half and vertices of the right half are pairwise connected, and $$$f(S)$$$ for any non-empty subset is $$$2$$$, thus the greatest common divisor of these values if also equal to $$$2$$$.In the second sample case the subset $$$\{1\}$$$ in the left half is connected to vertices $$$\{1, 2\}$$$ of the right half, with the sum of numbers equal to $$$2$$$, and the subset $$$\{1, 2\}$$$ in the left half is connected to vertices $$$\{1, 2, 3\}$$$ of the right half, with the sum of numbers equal to $$$3$$$. Thus, $$$f(\{1\}) = 2$$$, $$$f(\{1, 2\}) = 3$$$, which means that the greatest common divisor of all values of $$$f(S)$$$ is $$$1$$$.


Berland — is a huge country with diverse geography. One of the most famous natural attractions of Berland is the "Median mountain range". This mountain range is $$$n$$$ mountain peaks, located on one straight line and numbered in order of $$$1$$$ to $$$n$$$. The height of the $$$i$$$-th mountain top is $$$a_i$$$. "Median mountain range" is famous for the so called alignment of mountain peaks happening to it every day. At the moment of alignment simultaneously for each mountain from $$$2$$$ to $$$n - 1$$$ its height becomes equal to the median height among it and two neighboring mountains. Formally, if before the alignment the heights were equal $$$b_i$$$, then after the alignment new heights $$$a_i$$$ are as follows: $$$a_1 = b_1$$$, $$$a_n = b_n$$$ and for all $$$i$$$ from $$$2$$$ to $$$n - 1$$$ $$$a_i = \texttt{median}(b_{i-1}, b_i, b_{i+1})$$$. The median of three integers is the second largest number among them. For example, $$$\texttt{median}(5,1,2) = 2$$$, and $$$\texttt{median}(4,2,4) = 4$$$.Recently, Berland scientists have proved that whatever are the current heights of the mountains, the alignment process will stabilize sooner or later, i.e. at some point the altitude of the mountains won't changing after the alignment any more. The government of Berland wants to understand how soon it will happen, i.e. to find the value of $$$c$$$ — how many alignments will occur, which will change the height of at least one mountain. Also, the government of Berland needs to determine the heights of the mountains after $$$c$$$ alignments, that is, find out what heights of the mountains stay forever. Help scientists solve this important problem!

The first line contains integers $$$n$$$ ($$$1 \le n \le 500\,000$$$) — the number of mountains. The second line contains integers $$$a_1, a_2, a_3, \ldots, a_n$$$ ($$$1 \le a_i \le 10^9$$$) — current heights of the mountains.

In the first line print $$$c$$$ — the number of alignments, which change the height of at least one mountain. In the second line print $$$n$$$ integers — the final heights of the mountains after $$$c$$$ alignments.

NoteIn the first example, the heights of the mountains at index $$$1$$$ and $$$5$$$ never change. Since the median of $$$1$$$, $$$2$$$, $$$1$$$ is $$$1$$$, the second and the fourth mountains will have height 1 after the first alignment, and since the median of $$$2$$$, $$$1$$$, $$$2$$$ is $$$2$$$, the third mountain will have height 2 after the first alignment. This way, after one alignment the heights are $$$1$$$, $$$1$$$, $$$2$$$, $$$1$$$, $$$1$$$. After the second alignment the heights change into $$$1$$$, $$$1$$$, $$$1$$$, $$$1$$$, $$$1$$$ and never change from now on, so there are only $$$2$$$ alignments changing the mountain heights.In the third examples the alignment doesn't change any mountain height, so the number of alignments changing any height is $$$0$$$.


Polycarp plays a well-known computer game (we won't mention its name). Every object in this game consists of three-dimensional blocks — axis-aligned cubes of size $$$1 \times 1 \times 1$$$. These blocks are unaffected by gravity, so they can float in the air without support. The blocks are placed in cells of size $$$1 \times 1 \times 1$$$; each cell either contains exactly one block or is empty. Each cell is represented by its coordinates $$$(x, y, z)$$$ (the cell with these coordinates is a cube with opposite corners in $$$(x, y, z)$$$ and $$$(x + 1, y + 1, z + 1)$$$) and its contents $$$a_{x, y, z}$$$; if the cell is empty, then $$$a_{x, y, z} = 0$$$, otherwise $$$a_{x, y, z}$$$ is equal to the type of the block placed in it (the types are integers from $$$1$$$ to $$$2 \cdot 10^5$$$).Polycarp has built a large structure consisting of blocks. This structure can be enclosed in an axis-aligned rectangular parallelepiped of size $$$n \times m \times k$$$, containing all cells $$$(x, y, z)$$$ such that $$$x \in [1, n]$$$, $$$y \in [1, m]$$$, and $$$z \in [1, k]$$$. After that, Polycarp has installed $$$2nm + 2nk + 2mk$$$ sensors around this parallelepiped. A sensor is a special block that sends a ray in some direction and shows the type of the first block that was hit by this ray (except for other sensors). The sensors installed by Polycarp are adjacent to the borders of the parallelepiped, and the rays sent by them are parallel to one of the coordinate axes and directed inside the parallelepiped. More formally, the sensors can be divided into $$$6$$$ types:  there are $$$mk$$$ sensors of the first type; each such sensor is installed in $$$(0, y, z)$$$, where $$$y \in [1, m]$$$ and $$$z \in [1, k]$$$, and it sends a ray that is parallel to the $$$Ox$$$ axis and has the same direction;  there are $$$mk$$$ sensors of the second type; each such sensor is installed in $$$(n + 1, y, z)$$$, where $$$y \in [1, m]$$$ and $$$z \in [1, k]$$$, and it sends a ray that is parallel to the $$$Ox$$$ axis and has the opposite direction;  there are $$$nk$$$ sensors of the third type; each such sensor is installed in $$$(x, 0, z)$$$, where $$$x \in [1, n]$$$ and $$$z \in [1, k]$$$, and it sends a ray that is parallel to the $$$Oy$$$ axis and has the same direction;  there are $$$nk$$$ sensors of the fourth type; each such sensor is installed in $$$(x, m + 1, z)$$$, where $$$x \in [1, n]$$$ and $$$z \in [1, k]$$$, and it sends a ray that is parallel to the $$$Oy$$$ axis and has the opposite direction;  there are $$$nm$$$ sensors of the fifth type; each such sensor is installed in $$$(x, y, 0)$$$, where $$$x \in [1, n]$$$ and $$$y \in [1, m]$$$, and it sends a ray that is parallel to the $$$Oz$$$ axis and has the same direction;  finally, there are $$$nm$$$ sensors of the sixth type; each such sensor is installed in $$$(x, y, k + 1)$$$, where $$$x \in [1, n]$$$ and $$$y \in [1, m]$$$, and it sends a ray that is parallel to the $$$Oz$$$ axis and has the opposite direction. Polycarp has invited his friend Monocarp to play with him. Of course, as soon as Monocarp saw a large parallelepiped bounded by sensor blocks, he began to wonder what was inside of it. Polycarp didn't want to tell Monocarp the exact shape of the figure, so he provided Monocarp with the data from all sensors and told him to try guessing the contents of the parallelepiped by himself.After some hours of thinking, Monocarp has no clue about what's inside the sensor-bounded space. But he does not want to give up, so he decided to ask for help. Can you write a program that will analyze the sensor data and construct any figure that is consistent with it?

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \le n, m, k \le 2 \cdot 10^5$$$, $$$nmk \le 2 \cdot 10^5$$$) — the dimensions of the parallelepiped. Then the sensor data follows. For each sensor, its data is either $$$0$$$, if the ray emitted from it reaches the opposite sensor (there are no blocks in between), or an integer from $$$1$$$ to $$$2 \cdot 10^5$$$ denoting the type of the first block hit by the ray. The data is divided into $$$6$$$ sections (one for each type of sensors), each consecutive pair of sections is separated by a blank line, and the first section is separated by a blank line from the first line of the input. The first section consists of $$$m$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(0, i, j)$$$. The second section consists of $$$m$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(n + 1, i, j)$$$. The third section consists of $$$n$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, 0, j)$$$. The fourth section consists of $$$n$$$ lines containing $$$k$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, m + 1, j)$$$. The fifth section consists of $$$n$$$ lines containing $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, j, 0)$$$. Finally, the sixth section consists of $$$n$$$ lines containing $$$m$$$ integers each. The $$$j$$$-th integer in the $$$i$$$-th line is the data from the sensor installed in $$$(i, j, k + 1)$$$.

If the information from the input is inconsistent, print one integer $$$-1$$$. Otherwise, print the figure inside the parallelepiped as follows. The output should consist of $$$nmk$$$ integers: $$$a_{1, 1, 1}$$$, $$$a_{1, 1, 2}$$$, ..., $$$a_{1, 1, k}$$$, $$$a_{1, 2, 1}$$$, ..., $$$a_{1, 2, k}$$$, ..., $$$a_{1, m, k}$$$, $$$a_{2, 1, 1}$$$, ..., $$$a_{n, m, k}$$$, where $$$a_{i, j, k}$$$ is the type of the block in $$$(i, j, k)$$$, or $$$0$$$ if there is no block there. If there are multiple figures consistent with sensor data, describe any of them. For your convenience, the sample output is formatted as follows: there are $$$n$$$ separate sections for blocks having $$$x = 1$$$, $$$x = 2$$$, ..., $$$x = n$$$; each section consists of $$$m$$$ lines containing $$$k$$$ integers each. Note that this type of output is acceptable, but you may print the integers with any other formatting instead (even all integers on the same line), only their order matters.


You are given an array $$$a$$$ consisting of $$$n$$$ positive integers. Find a non-empty subset of its elements such that their sum is even (i.e. divisible by $$$2$$$) or determine that there is no such subset.Both the given array and required subset may contain equal values.

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$), number of test cases to solve. Descriptions of $$$t$$$ test cases follow. A description of each test case consists of two lines. The first line contains a single integer $$$n$$$ ($$$1 \leq n \leq 100$$$), length of array $$$a$$$. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$1 \leq a_i \leq 100$$$), elements of $$$a$$$. The given array $$$a$$$ can contain equal values (duplicates).

For each test case output $$$-1$$$ if there is no such subset of elements. Otherwise output positive integer $$$k$$$, number of elements in the required subset. Then output $$$k$$$ distinct integers ($$$1 \leq p_i \leq n$$$), indexes of the chosen elements. If there are multiple solutions output any of them.

NoteThere are three test cases in the example.In the first test case, you can choose the subset consisting of only the second element. Its sum is $$$4$$$ and it is even.In the second test case, there is only one non-empty subset of elements consisting of the first element, however sum in it is odd, so there is no solution.In the third test case, the subset consisting of all array's elements has even sum.


Mayor of city M. decided to launch several new metro lines during 2020. Since the city has a very limited budget, it was decided not to dig new tunnels but to use the existing underground network.The tunnel system of the city M. consists of $$$n$$$ metro stations. The stations are connected with $$$n - 1$$$ bidirectional tunnels. Between every two stations $$$v$$$ and $$$u$$$ there is exactly one simple path. Each metro line the mayor wants to create is a simple path between stations $$$a_i$$$ and $$$b_i$$$. Metro lines can intersects freely, that is, they can share common stations or even common tunnels. However, it's not yet decided which of two directions each line will go. More precisely, between the stations $$$a_i$$$ and $$$b_i$$$ the trains will go either from $$$a_i$$$ to $$$b_i$$$, or from $$$b_i$$$ to $$$a_i$$$, but not simultaneously.The city $$$M$$$ uses complicated faring rules. Each station is assigned with a positive integer $$$c_i$$$ — the fare zone of the station. The cost of travel from $$$v$$$ to $$$u$$$ is defined as $$$c_u - c_v$$$ roubles. Of course, such travel only allowed in case there is a metro line, the trains on which go from $$$v$$$ to $$$u$$$. Mayor doesn't want to have any travels with a negative cost, so it was decided to assign directions of metro lines and station fare zones in such a way, that fare zones are strictly increasing during any travel on any metro line.Mayor wants firstly assign each station a fare zone and then choose a lines direction, such that all fare zones are increasing along any line. In connection with the approaching celebration of the day of the city, the mayor wants to assign fare zones so that the maximum $$$c_i$$$ will be as low as possible. Please help mayor to design a new assignment or determine if it's impossible to do. Please note that you only need to assign the fare zones optimally, you don't need to print lines' directions. This way, you solution will be considered correct if there will be a way to assign directions of every metro line, so that the fare zones will be strictly increasing along any movement of the trains.

The first line contains an integers $$$n$$$, $$$m$$$ ($$$2 \le n, \le 500\,000,\ 1 \le m \le 500\,000$$$) — the number of stations in the city and the number of metro lines. Each of the following $$$n-1$$$ lines describes another metro tunnel. Each tunnel is described with integers $$$v_i$$$, $$$u_i$$$ ($$$1 \le v_i,\ u_i \le n$$$, $$$v_i \ne u_i$$$). It's guaranteed, that there is exactly one simple path between any two stations. Each of the following $$$m$$$ lines describes another metro line. Each line is described with integers $$$a_i$$$, $$$b_i$$$ ($$$1 \le a_i,\ b_i \le n$$$, $$$a_i \neq b_i$$$).

In the first line print integer $$$k$$$ — the maximum fare zone used. In the next line print integers $$$c_1, c_2, \ldots, c_n$$$ ($$$1 \le c_i \le k$$$)  — stations' fare zones.  In case there are several possible answers, print any of them. In case it's impossible to assign fare zones, print "-1".

NoteIn the first example, line $$$1 \rightarrow 3$$$ goes through the stations 1, 2, 3 in this order. In this order the fare zones of the stations are increasing. Since this line has 3 stations, at least three fare zones are needed. So the answer 1, 2, 3 is optimal.In the second example, it's impossible to assign fare zones to be consistent with a metro lines.


You are given an array $$$a$$$ consisting of $$$n$$$ integers.Your task is to determine if $$$a$$$ has some subsequence of length at least $$$3$$$ that is a palindrome.Recall that an array $$$b$$$ is called a subsequence of the array $$$a$$$ if $$$b$$$ can be obtained by removing some (possibly, zero) elements from $$$a$$$ (not necessarily consecutive) without changing the order of remaining elements. For example, $$$[2]$$$, $$$[1, 2, 1, 3]$$$ and $$$[2, 3]$$$ are subsequences of $$$[1, 2, 1, 3]$$$, but $$$[1, 1, 2]$$$ and $$$[4]$$$ are not.Also, recall that a palindrome is an array that reads the same backward as forward. In other words, the array $$$a$$$ of length $$$n$$$ is the palindrome if $$$a_i = a_{n - i - 1}$$$ for all $$$i$$$ from $$$1$$$ to $$$n$$$. For example, arrays $$$[1234]$$$, $$$[1, 2, 1]$$$, $$$[1, 3, 2, 2, 3, 1]$$$ and $$$[10, 100, 10]$$$ are palindromes, but arrays $$$[1, 2]$$$ and $$$[1, 2, 3, 1]$$$ are not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. Next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$3 \le n \le 5000$$$) — the length of $$$a$$$. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$), where $$$a_i$$$ is the $$$i$$$-th element of $$$a$$$. It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$5000$$$ ($$$\sum n \le 5000$$$).

For each test case, print the answer — "YES" (without quotes) if $$$a$$$ has some subsequence of length at least $$$3$$$ that is a palindrome and "NO" otherwise.

NoteIn the first test case of the example, the array $$$a$$$ has a subsequence $$$[1, 2, 1]$$$ which is a palindrome.In the second test case of the example, the array $$$a$$$ has two subsequences of length $$$3$$$ which are palindromes: $$$[2, 3, 2]$$$ and $$$[2, 2, 2]$$$.In the third test case of the example, the array $$$a$$$ has no subsequences of length at least $$$3$$$ which are palindromes.In the fourth test case of the example, the array $$$a$$$ has one subsequence of length $$$4$$$ which is a palindrome: $$$[1, 2, 2, 1]$$$ (and has two subsequences of length $$$3$$$ which are palindromes: both are $$$[1, 2, 1]$$$).In the fifth test case of the example, the array $$$a$$$ has no subsequences of length at least $$$3$$$ which are palindromes.


You are given some Tetris field consisting of $$$n$$$ columns. The initial height of the $$$i$$$-th column of the field is $$$a_i$$$ blocks. On top of these columns you can place only figures of size $$$2 \times 1$$$ (i.e. the height of this figure is $$$2$$$ blocks and the width of this figure is $$$1$$$ block). Note that you cannot rotate these figures.Your task is to say if you can clear the whole field by placing such figures.More formally, the problem can be described like this:The following process occurs while at least one $$$a_i$$$ is greater than $$$0$$$:  You place one figure $$$2 \times 1$$$ (choose some $$$i$$$ from $$$1$$$ to $$$n$$$ and replace $$$a_i$$$ with $$$a_i + 2$$$);  then, while all $$$a_i$$$ are greater than zero, replace each $$$a_i$$$ with $$$a_i - 1$$$. And your task is to determine if it is possible to clear the whole field (i.e. finish the described process), choosing the places for new figures properly.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases. The next $$$2t$$$ lines describe test cases. The first line of the test case contains one integer $$$n$$$ ($$$1 \le n \le 100$$$) — the number of columns in the Tetris field. The second line of the test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 100$$$), where $$$a_i$$$ is the initial height of the $$$i$$$-th column of the Tetris field.

For each test case, print the answer — "YES" (without quotes) if you can clear the whole Tetris field and "NO" otherwise.

NoteThe first test case of the example field is shown below:Gray lines are bounds of the Tetris field. Note that the field has no upper bound.One of the correct answers is to first place the figure in the first column. Then after the second step of the process, the field becomes $$$[2, 0, 2]$$$. Then place the figure in the second column and after the second step of the process, the field becomes $$$[0, 0, 0]$$$.And the second test case of the example field is shown below:It can be shown that you cannot do anything to end the process.In the third test case of the example, you first place the figure in the second column after the second step of the process, the field becomes $$$[0, 2]$$$. Then place the figure in the first column and after the second step of the process, the field becomes $$$[0, 0]$$$.In the fourth test case of the example, place the figure in the first column, then the field becomes $$$[102]$$$ after the first step of the process, and then the field becomes $$$[0]$$$ after the second step of the process.


There is a frog staying to the left of the string $$$s = s_1 s_2 \ldots s_n$$$ consisting of $$$n$$$ characters (to be more precise, the frog initially stays at the cell $$$0$$$). Each character of $$$s$$$ is either 'L' or 'R'. It means that if the frog is staying at the $$$i$$$-th cell and the $$$i$$$-th character is 'L', the frog can jump only to the left. If the frog is staying at the $$$i$$$-th cell and the $$$i$$$-th character is 'R', the frog can jump only to the right. The frog can jump only to the right from the cell $$$0$$$.Note that the frog can jump into the same cell twice and can perform as many jumps as it needs.The frog wants to reach the $$$n+1$$$-th cell. The frog chooses some positive integer value $$$d$$$ before the first jump (and cannot change it later) and jumps by no more than $$$d$$$ cells at once. I.e. if the $$$i$$$-th character is 'L' then the frog can jump to any cell in a range $$$[max(0, i - d); i - 1]$$$, and if the $$$i$$$-th character is 'R' then the frog can jump to any cell in a range $$$[i + 1; min(n + 1; i + d)]$$$.The frog doesn't want to jump far, so your task is to find the minimum possible value of $$$d$$$ such that the frog can reach the cell $$$n+1$$$ from the cell $$$0$$$ if it can jump by no more than $$$d$$$ cells at once. It is guaranteed that it is always possible to reach $$$n+1$$$ from $$$0$$$.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The $$$i$$$-th test case is described as a string $$$s$$$ consisting of at least $$$1$$$ and at most $$$2 \cdot 10^5$$$ characters 'L' and 'R'. It is guaranteed that the sum of lengths of strings over all test cases does not exceed $$$2 \cdot 10^5$$$ ($$$\sum |s| \le 2 \cdot 10^5$$$).

For each test case, print the answer — the minimum possible value of $$$d$$$ such that the frog can reach the cell $$$n+1$$$ from the cell $$$0$$$ if it jumps by no more than $$$d$$$ at once.

NoteThe picture describing the first test case of the example and one of the possible answers:In the second test case of the example, the frog can only jump directly from $$$0$$$ to $$$n+1$$$.In the third test case of the example, the frog can choose $$$d=3$$$, jump to the cell $$$3$$$ from the cell $$$0$$$ and then to the cell $$$4$$$ from the cell $$$3$$$.In the fourth test case of the example, the frog can choose $$$d=1$$$ and jump $$$5$$$ times to the right.In the fifth test case of the example, the frog can only jump directly from $$$0$$$ to $$$n+1$$$.In the sixth test case of the example, the frog can choose $$$d=1$$$ and jump $$$2$$$ times to the right.


You are given an array $$$a$$$ of length $$$n$$$ and array $$$b$$$ of length $$$m$$$ both consisting of only integers $$$0$$$ and $$$1$$$. Consider a matrix $$$c$$$ of size $$$n \times m$$$ formed by following rule: $$$c_{i, j} = a_i \cdot b_j$$$ (i.e. $$$a_i$$$ multiplied by $$$b_j$$$). It's easy to see that $$$c$$$ consists of only zeroes and ones too.How many subrectangles of size (area) $$$k$$$ consisting only of ones are there in $$$c$$$?A subrectangle is an intersection of a consecutive (subsequent) segment of rows and a consecutive (subsequent) segment of columns. I.e. consider four integers $$$x_1, x_2, y_1, y_2$$$ ($$$1 \le x_1 \le x_2 \le n$$$, $$$1 \le y_1 \le y_2 \le m$$$) a subrectangle $$$c[x_1 \dots x_2][y_1 \dots y_2]$$$ is an intersection of the rows $$$x_1, x_1+1, x_1+2, \dots, x_2$$$ and the columns $$$y_1, y_1+1, y_1+2, \dots, y_2$$$.The size (area) of a subrectangle is the total number of cells in it.

The first line contains three integers $$$n$$$, $$$m$$$ and $$$k$$$ ($$$1 \leq n, m \leq 40\,000, 1 \leq k \leq n \cdot m$$$), length of array $$$a$$$, length of array $$$b$$$ and required size of subrectangles. The second line contains $$$n$$$ integers $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 1$$$), elements of $$$a$$$. The third line contains $$$m$$$ integers $$$b_1, b_2, \ldots, b_m$$$ ($$$0 \leq b_i \leq 1$$$), elements of $$$b$$$.

Output single integer — the number of subrectangles of $$$c$$$ with size (area) $$$k$$$ consisting only of ones.

NoteIn first example matrix $$$c$$$ is:  There are $$$4$$$ subrectangles of size $$$2$$$ consisting of only ones in it:  In second example matrix $$$c$$$ is:


A bracketed sequence is called correct (regular) if by inserting "+" and "1" you can get a well-formed mathematical expression from it. For example, sequences "(())()", "()" and "(()(()))" are correct, while ")(", "(()" and "(()))(" are not.The teacher gave Dmitry's class a very strange task — she asked every student to come up with a sequence of arbitrary length, consisting only of opening and closing brackets. After that all the students took turns naming the sequences they had invented. When Dima's turn came, he suddenly realized that all his classmates got the correct bracketed sequence, and whether he got the correct bracketed sequence, he did not know.Dima suspects now that he simply missed the word "correct" in the task statement, so now he wants to save the situation by modifying his sequence slightly. More precisely, he can the arbitrary number of times (possibly zero) perform the reorder operation.The reorder operation consists of choosing an arbitrary consecutive subsegment (substring) of the sequence and then reordering all the characters in it in an arbitrary way. Such operation takes $$$l$$$ nanoseconds, where $$$l$$$ is the length of the subsegment being reordered. It's easy to see that reorder operation doesn't change the number of opening and closing brackets. For example for "))((" he can choose the substring ")(" and do reorder ")()(" (this operation will take $$$2$$$ nanoseconds).Since Dima will soon have to answer, he wants to make his sequence correct as fast as possible. Help him to do this, or determine that it's impossible.

The first line contains a single integer $$$n$$$ ($$$1 \le n \le 10^6$$$) — the length of Dima's sequence. The second line contains string of length $$$n$$$, consisting of characters "(" and ")" only.

Print a single integer — the minimum number of nanoseconds to make the sequence correct or "-1" if it is impossible to do so.

NoteIn the first example we can firstly reorder the segment from first to the fourth character, replacing it with "()()", the whole sequence will be "()()())(". And then reorder the segment from the seventh to eighth character, replacing it with "()". In the end the sequence will be "()()()()", while the total time spent is $$$4 + 2 = 6$$$ nanoseconds.


The next lecture in a high school requires two topics to be discussed. The $$$i$$$-th topic is interesting by $$$a_i$$$ units for the teacher and by $$$b_i$$$ units for the students.The pair of topics $$$i$$$ and $$$j$$$ ($$$i < j$$$) is called good if $$$a_i + a_j > b_i + b_j$$$ (i.e. it is more interesting for the teacher).Your task is to find the number of good pairs of topics.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of topics. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is the interestingness of the $$$i$$$-th topic for the teacher. The third line of the input contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le 10^9$$$), where $$$b_i$$$ is the interestingness of the $$$i$$$-th topic for the students.

Print one integer — the number of good pairs of topic.


Vova had a pretty weird sleeping schedule. There are $$$h$$$ hours in a day. Vova will sleep exactly $$$n$$$ times. The $$$i$$$-th time he will sleep exactly after $$$a_i$$$ hours from the time he woke up. You can assume that Vova woke up exactly at the beginning of this story (the initial time is $$$0$$$). Each time Vova sleeps exactly one day (in other words, $$$h$$$ hours).Vova thinks that the $$$i$$$-th sleeping time is good if he starts to sleep between hours $$$l$$$ and $$$r$$$ inclusive.Vova can control himself and before the $$$i$$$-th time can choose between two options: go to sleep after $$$a_i$$$ hours or after $$$a_i - 1$$$ hours.Your task is to say the maximum number of good sleeping times Vova can obtain if he acts optimally.

The first line of the input contains four integers $$$n, h, l$$$ and $$$r$$$ ($$$1 \le n \le 2000, 3 \le h \le 2000, 0 \le l \le r < h$$$) — the number of times Vova goes to sleep, the number of hours in a day and the segment of the good sleeping time. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i < h$$$), where $$$a_i$$$ is the number of hours after which Vova goes to sleep the $$$i$$$-th time.

Print one integer — the maximum number of good sleeping times Vova can obtain if he acts optimally.

NoteThe maximum number of good times in the example is $$$3$$$.The story starts from $$$t=0$$$. Then Vova goes to sleep after $$$a_1 - 1$$$ hours, now the time is $$$15$$$. This time is not good. Then Vova goes to sleep after $$$a_2 - 1$$$ hours, now the time is $$$15 + 16 = 7$$$. This time is also not good. Then Vova goes to sleep after $$$a_3$$$ hours, now the time is $$$7 + 14 = 21$$$. This time is good. Then Vova goes to sleep after $$$a_4 - 1$$$ hours, now the time is $$$21 + 19 = 16$$$. This time is not good. Then Vova goes to sleep after $$$a_5$$$ hours, now the time is $$$16 + 20 = 12$$$. This time is not good. Then Vova goes to sleep after $$$a_6$$$ hours, now the time is $$$12 + 11 = 23$$$. This time is good. Then Vova goes to sleep after $$$a_7$$$ hours, now the time is $$$23 + 22 = 21$$$. This time is also good.


You are given a tree consisting of $$$n$$$ vertices. A tree is a connected undirected graph with $$$n-1$$$ edges. Each vertex $$$v$$$ of this tree has a color assigned to it ($$$a_v = 1$$$ if the vertex $$$v$$$ is white and $$$0$$$ if the vertex $$$v$$$ is black).You have to solve the following problem for each vertex $$$v$$$: what is the maximum difference between the number of white and the number of black vertices you can obtain if you choose some subtree of the given tree that contains the vertex $$$v$$$? The subtree of the tree is the connected subgraph of the given tree. More formally, if you choose the subtree that contains $$$cnt_w$$$ white vertices and $$$cnt_b$$$ black vertices, you have to maximize $$$cnt_w - cnt_b$$$.

The first line of the input contains one integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 1$$$), where $$$a_i$$$ is the color of the $$$i$$$-th vertex. Each of the next $$$n-1$$$ lines describes an edge of the tree. Edge $$$i$$$ is denoted by two integers $$$u_i$$$ and $$$v_i$$$, the labels of vertices it connects $$$(1 \le u_i, v_i \le n, u_i \ne v_i$$$). It is guaranteed that the given edges form a tree.

Print $$$n$$$ integers $$$res_1, res_2, \dots, res_n$$$, where $$$res_i$$$ is the maximum possible difference between the number of white and black vertices in some subtree that contains the vertex $$$i$$$.

NoteThe first example is shown below:The black vertices have bold borders.In the second example, the best subtree for vertices $$$2, 3$$$ and $$$4$$$ are vertices $$$2, 3$$$ and $$$4$$$ correspondingly. And the best subtree for the vertex $$$1$$$ is the subtree consisting of vertices $$$1$$$ and $$$3$$$.


You are given a positive integer $$$x$$$. Find any such $$$2$$$ positive integers $$$a$$$ and $$$b$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$.As a reminder, $$$GCD(a,b)$$$ is the greatest integer that divides both $$$a$$$ and $$$b$$$. Similarly, $$$LCM(a,b)$$$ is the smallest integer such that both $$$a$$$ and $$$b$$$ divide it.It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

The first line contains a single integer $$$t$$$ $$$(1 \le t \le 100)$$$  — the number of testcases. Each testcase consists of one line containing a single integer, $$$x$$$ $$$(2 \le x \le 10^9)$$$.

For each testcase, output a pair of positive integers $$$a$$$ and $$$b$$$ ($$$1 \le a, b \le 10^9)$$$ such that $$$GCD(a,b)+LCM(a,b)=x$$$. It's guaranteed that the solution always exists. If there are several such pairs $$$(a, b)$$$, you can output any of them.

NoteIn the first testcase of the sample, $$$GCD(1,1)+LCM(1,1)=1+1=2$$$.In the second testcase of the sample, $$$GCD(6,4)+LCM(6,4)=2+12=14$$$.


Ehab has an array $$$a$$$ of length $$$n$$$. He has just enough free time to make a new array consisting of $$$n$$$ copies of the old array, written back-to-back. What will be the length of the new array's longest increasing subsequence?A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements. The longest increasing subsequence of an array is the longest subsequence such that its elements are ordered in strictly increasing order.

The first line contains an integer $$$t$$$ — the number of test cases you need to solve. The description of the test cases follows. The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the number of elements in the array $$$a$$$. The second line contains $$$n$$$ space-separated integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^9$$$) — the elements of the array $$$a$$$. The sum of $$$n$$$ across the test cases doesn't exceed $$$10^5$$$.

For each testcase, output the length of the longest increasing subsequence of $$$a$$$ if you concatenate it to itself $$$n$$$ times.

NoteIn the first sample, the new array is $$$[3,2,\textbf{1},3,\textbf{2},1,\textbf{3},2,1]$$$. The longest increasing subsequence is marked in bold.In the second sample, the longest increasing subsequence will be $$$[1,3,4,5,9]$$$.


You are given a tree consisting of $$$n$$$ nodes. You want to write some labels on the tree's edges such that the following conditions hold:  Every label is an integer between $$$0$$$ and $$$n-2$$$ inclusive.  All the written labels are distinct.  The largest value among $$$MEX(u,v)$$$ over all pairs of nodes $$$(u,v)$$$ is as small as possible. Here, $$$MEX(u,v)$$$ denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node $$$u$$$ to node $$$v$$$.

The first line contains the integer $$$n$$$ ($$$2 \le n \le 10^5$$$) — the number of nodes in the tree. Each of the next $$$n-1$$$ lines contains two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) that mean there's an edge between nodes $$$u$$$ and $$$v$$$. It's guaranteed that the given graph is a tree.

Output $$$n-1$$$ integers. The $$$i^{th}$$$ of them will be the number written on the $$$i^{th}$$$ edge (in the input order).


Given 2 integers $$$u$$$ and $$$v$$$, find the shortest array such that bitwise-xor of its elements is $$$u$$$, and the sum of its elements is $$$v$$$.

The only line contains 2 integers $$$u$$$ and $$$v$$$ $$$(0 \le u,v \le 10^{18})$$$.

If there's no array that satisfies the condition, print "-1". Otherwise: The first line should contain one integer, $$$n$$$, representing the length of the desired array. The next line should contain $$$n$$$ positive integers, the array itself. If there are multiple possible answers, print any.

NoteIn the first sample, $$$3\oplus 1 = 2$$$ and $$$3 + 1 = 4$$$. There is no valid array of smaller length.Notice that in the fourth sample the array is empty.


You are given a integer $$$n$$$ ($$$n > 0$$$). Find any integer $$$s$$$ which satisfies these conditions, or report that there are no such numbers:In the decimal representation of $$$s$$$:   $$$s > 0$$$,  $$$s$$$ consists of $$$n$$$ digits,  no digit in $$$s$$$ equals $$$0$$$,  $$$s$$$ is not divisible by any of it's digits.

The input consists of multiple test cases. The first line of the input contains a single integer $$$t$$$ ($$$1 \leq t \leq 400$$$), the number of test cases. The next $$$t$$$ lines each describe a test case. Each test case contains one positive integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$). It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$10^5$$$.

For each test case, print an integer $$$s$$$ which satisfies the conditions described above, or "-1" (without quotes), if no such number exists. If there are multiple possible solutions for $$$s$$$, print any solution.


You are given an array $$$a$$$ of length $$$n$$$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.A sequence $$$a$$$ is a subsequence of an array $$$b$$$ if $$$a$$$ can be obtained from $$$b$$$ by deletion of several (possibly, zero or all) elements.

The first line contains an integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the length of $$$a$$$. The second line contains $$$n$$$ integers $$$a_1$$$, $$$a_2$$$, $$$\ldots$$$, $$$a_{n}$$$ ($$$1 \le a_i \le 10^6$$$) — the elements of the array $$$a$$$.

Output the length of the shortest non-empty subsequence of $$$a$$$ product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1".

NoteIn the first sample, you can choose a subsequence $$$[1]$$$.In the second sample, you can choose a subsequence $$$[6, 6]$$$.In the third sample, you can choose a subsequence $$$[6, 15, 10]$$$.In the fourth sample, there is no such subsequence.


Alicia has an array, $$$a_1, a_2, \ldots, a_n$$$, of non-negative integers. For each $$$1 \leq i \leq n$$$, she has found a non-negative integer $$$x_i = max(0, a_1, \ldots, a_{i-1})$$$. Note that for $$$i=1$$$, $$$x_i = 0$$$.For example, if Alicia had the array $$$a = \{0, 1, 2, 0, 3\}$$$, then $$$x = \{0, 0, 1, 2, 2\}$$$.Then, she calculated an array, $$$b_1, b_2, \ldots, b_n$$$: $$$b_i = a_i - x_i$$$.For example, if Alicia had the array $$$a = \{0, 1, 2, 0, 3\}$$$, $$$b = \{0-0, 1-0, 2-1, 0-2, 3-2\} = \{0, 1, 1, -2, 1\}$$$.Alicia gives you the values $$$b_1, b_2, \ldots, b_n$$$ and asks you to restore the values $$$a_1, a_2, \ldots, a_n$$$. Can you help her solve the problem?

The first line contains one integer $$$n$$$ ($$$3 \leq n \leq 200\,000$$$) – the number of elements in Alicia's array. The next line contains $$$n$$$ integers, $$$b_1, b_2, \ldots, b_n$$$ ($$$-10^9 \leq b_i \leq 10^9$$$). It is guaranteed that for the given array $$$b$$$ there is a solution $$$a_1, a_2, \ldots, a_n$$$, for all elements of which the following is true: $$$0 \leq a_i \leq 10^9$$$.

Print $$$n$$$ integers, $$$a_1, a_2, \ldots, a_n$$$ ($$$0 \leq a_i \leq 10^9$$$), such that if you calculate $$$x$$$ according to the statement, $$$b_1$$$ will be equal to $$$a_1 - x_1$$$, $$$b_2$$$ will be equal to $$$a_2 - x_2$$$, ..., and $$$b_n$$$ will be equal to $$$a_n - x_n$$$. It is guaranteed that there exists at least one solution for the given tests. It can be shown that the solution is unique.


You are given a permutation $$$p_1, p_2, \ldots, p_n$$$ of integers from $$$1$$$ to $$$n$$$ and an integer $$$k$$$, such that $$$1 \leq k \leq n$$$. A permutation means that every number from $$$1$$$ to $$$n$$$ is contained in $$$p$$$ exactly once.Let's consider all partitions of this permutation into $$$k$$$ disjoint segments. Formally, a partition is a set of segments $$$\{[l_1, r_1], [l_2, r_2], \ldots, [l_k, r_k]\}$$$, such that:  $$$1 \leq l_i \leq r_i \leq n$$$ for all $$$1 \leq i \leq k$$$;  For all $$$1 \leq j \leq n$$$ there exists exactly one segment $$$[l_i, r_i]$$$, such that $$$l_i \leq j \leq r_i$$$. Two partitions are different if there exists a segment that lies in one partition but not the other.Let's calculate the partition value, defined as $$$\sum\limits_{i=1}^{k} {\max\limits_{l_i \leq j \leq r_i} {p_j}}$$$, for all possible partitions of the permutation into $$$k$$$ disjoint segments. Find the maximum possible partition value over all such partitions, and the number of partitions with this value. As the second value can be very large, you should find its remainder when divided by $$$998\,244\,353$$$.

The first line contains two integers, $$$n$$$ and $$$k$$$ ($$$1 \leq k \leq n \leq 200\,000$$$) — the size of the given permutation and the number of segments in a partition. The second line contains $$$n$$$ different integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq n$$$) — the given permutation.

Print two integers — the maximum possible partition value over all partitions of the permutation into $$$k$$$ disjoint segments and the number of such partitions for which the partition value is equal to the maximum possible value, modulo $$$998\,244\,353$$$. Please note that you should only find the second value modulo $$$998\,244\,353$$$.

NoteIn the first test, for $$$k = 2$$$, there exists only two valid partitions: $$$\{[1, 1], [2, 3]\}$$$ and $$$\{[1, 2], [3, 3]\}$$$. For each partition, the partition value is equal to $$$2 + 3 = 5$$$. So, the maximum possible value is $$$5$$$ and the number of partitions is $$$2$$$.In the third test, for $$$k = 3$$$, the partitions with the maximum possible partition value are $$$\{[1, 2], [3, 5], [6, 7]\}$$$, $$$\{[1, 3], [4, 5], [6, 7]\}$$$, $$$\{[1, 4], [5, 5], [6, 7]\}$$$, $$$\{[1, 2], [3, 6], [7, 7]\}$$$, $$$\{[1, 3], [4, 6], [7, 7]\}$$$, $$$\{[1, 4], [5, 6], [7, 7]\}$$$. For all of them, the partition value is equal to $$$7 + 5 + 6 = 18$$$. The partition $$$\{[1, 2], [3, 4], [5, 7]\}$$$, however, has the partition value $$$7 + 3 + 6 = 16$$$. This is not the maximum possible value, so we don't count it.


This is the easy version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.You are given a string $$$s$$$, consisting of lowercase English letters. Find the longest string, $$$t$$$, which satisfies the following conditions:   The length of $$$t$$$ does not exceed the length of $$$s$$$.  $$$t$$$ is a palindrome.  There exists two strings $$$a$$$ and $$$b$$$ (possibly empty), such that $$$t = a + b$$$ ( "$$$+$$$" represents concatenation), and $$$a$$$ is prefix of $$$s$$$ while $$$b$$$ is suffix of $$$s$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 1000$$$), the number of test cases. The next $$$t$$$ lines each describe a test case. Each test case is a non-empty string $$$s$$$, consisting of lowercase English letters. It is guaranteed that the sum of lengths of strings over all test cases does not exceed $$$5000$$$.

For each test case, print the longest string which satisfies the conditions described above. If there exists multiple possible solutions, print any of them.

NoteIn the first test, the string $$$s = $$$"a" satisfies all conditions.In the second test, the string "abcdfdcba" satisfies all conditions, because:  Its length is $$$9$$$, which does not exceed the length of the string $$$s$$$, which equals $$$11$$$.  It is a palindrome.  "abcdfdcba" $$$=$$$ "abcdfdc" $$$+$$$ "ba", and "abcdfdc" is a prefix of $$$s$$$ while "ba" is a suffix of $$$s$$$. It can be proven that there does not exist a longer string which satisfies the conditions.In the fourth test, the string "c" is correct, because "c" $$$=$$$ "c" $$$+$$$ "" and $$$a$$$ or $$$b$$$ can be empty. The other possible solution for this test is "s".

5
a
abcdfdcecba
abbaxyzyx
codeforces
acbba


This is the hard version of the problem. The difference is the constraint on the sum of lengths of strings and the number of test cases. You can make hacks only if you solve all versions of this task.You are given a string $$$s$$$, consisting of lowercase English letters. Find the longest string, $$$t$$$, which satisfies the following conditions:   The length of $$$t$$$ does not exceed the length of $$$s$$$.  $$$t$$$ is a palindrome.  There exists two strings $$$a$$$ and $$$b$$$ (possibly empty), such that $$$t = a + b$$$ ( "$$$+$$$" represents concatenation), and $$$a$$$ is prefix of $$$s$$$ while $$$b$$$ is suffix of $$$s$$$.

The input consists of multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 10^5$$$), the number of test cases. The next $$$t$$$ lines each describe a test case. Each test case is a non-empty string $$$s$$$, consisting of lowercase English letters. It is guaranteed that the sum of lengths of strings over all test cases does not exceed $$$10^6$$$.


It's the year 5555. You have a graph, and you want to find a long cycle and a huge independent set, just because you can. But for now, let's just stick with finding either.Given a connected graph with $$$n$$$ vertices, you can choose to either:  find an independent set that has exactly $$$\lceil\sqrt{n}\rceil$$$ vertices. find a simple cycle of length at least $$$\lceil\sqrt{n}\rceil$$$. An independent set is a set of vertices such that no two of them are connected by an edge. A simple cycle is a cycle that doesn't contain any vertex twice. I have a proof you can always solve one of these problems, but it's too long to fit this margin.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$5 \le n \le 10^5$$$, $$$n-1 \le m \le 2 \cdot 10^5$$$) — the number of vertices and edges in the graph. Each of the next $$$m$$$ lines contains two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) that mean there's an edge between vertices $$$u$$$ and $$$v$$$. It's guaranteed that the graph is connected and doesn't contain any self-loops or multiple edges.

If you choose to solve the first problem, then on the first line print "1", followed by a line containing $$$\lceil\sqrt{n}\rceil$$$ distinct integers not exceeding $$$n$$$, the vertices in the desired independent set. If you, however, choose to solve the second problem, then on the first line print "2", followed by a line containing one integer, $$$c$$$, representing the length of the found cycle, followed by a line containing $$$c$$$ distinct integers integers not exceeding $$$n$$$, the vertices in the desired cycle, in the order they appear in the cycle.

NoteIn the first sample:Notice that you can solve either problem, so printing the cycle $$$2-4-3-1-5-6$$$ is also acceptable.In the second sample:Notice that if there are multiple answers you can print any, so printing the cycle $$$2-5-6$$$, for example, is acceptable.In the third sample:


This is the easy version of the problem. The difference is constraints on the number of wise men and the time limit. You can make hacks only if all versions of this task are solved.$$$n$$$ wise men live in a beautiful city. Some of them know each other.For each of the $$$n!$$$ possible permutations $$$p_1, p_2, \ldots, p_n$$$ of the wise men, let's generate a binary string of length $$$n-1$$$: for each $$$1 \leq i < n$$$ set $$$s_i=1$$$ if $$$p_i$$$ and $$$p_{i+1}$$$ know each other, and $$$s_i=0$$$ otherwise. For all possible $$$2^{n-1}$$$ binary strings, find the number of permutations that produce this binary string.

The first line of input contains one integer $$$n$$$ ($$$2 \leq n \leq 14)$$$  — the number of wise men in the city. The next $$$n$$$ lines contain a binary string of length $$$n$$$ each, such that the $$$j$$$-th character of the $$$i$$$-th string is equal to '1' if wise man $$$i$$$ knows wise man $$$j$$$, and equals '0' otherwise. It is guaranteed that if the $$$i$$$-th man knows the $$$j$$$-th man, then the $$$j$$$-th man knows $$$i$$$-th man and no man knows himself.

Print $$$2^{n-1}$$$ space-separated integers. For each $$$0 \leq x < 2^{n-1}$$$:   Let's consider a string $$$s$$$ of length $$$n-1$$$, such that $$$s_i = \lfloor \frac{x}{2^{i-1}} \rfloor \bmod 2$$$ for all $$$1 \leq i \leq n - 1$$$.  The $$$(x+1)$$$-th number should be equal to the required answer for $$$s$$$.

NoteIn the first test, each wise man knows each other, so every permutation will produce the string $$$11$$$.In the second test:  If $$$p = \{1, 2, 3, 4\}$$$, the produced string is $$$101$$$, because wise men $$$1$$$ and $$$2$$$ know each other, $$$2$$$ and $$$3$$$ don't know each other, and $$$3$$$ and $$$4$$$ know each other;  If $$$p = \{4, 1, 2, 3\}$$$, the produced string is $$$110$$$, because wise men $$$1$$$ and $$$4$$$ know each other, $$$1$$$ and $$$2$$$ know each other and $$$2$$$, and $$$3$$$ don't know each other;  If $$$p = \{1, 3, 2, 4\}$$$, the produced string is $$$000$$$, because wise men $$$1$$$ and $$$3$$$ don't know each other, $$$3$$$ and $$$2$$$ don't know each other, and $$$2$$$ and $$$4$$$ don't know each other.


This is the hard version of the problem. The difference is constraints on the number of wise men and the time limit. You can make hacks only if all versions of this task are solved.$$$n$$$ wise men live in a beautiful city. Some of them know each other.For each of the $$$n!$$$ possible permutations $$$p_1, p_2, \ldots, p_n$$$ of the wise men, let's generate a binary string of length $$$n-1$$$: for each $$$1 \leq i < n$$$ set $$$s_i=1$$$ if $$$p_i$$$ and $$$p_{i+1}$$$ know each other, and $$$s_i=0$$$ otherwise. For all possible $$$2^{n-1}$$$ binary strings, find the number of permutations that produce this binary string.

The first line of input contains one integer $$$n$$$ ($$$2 \leq n \leq 18)$$$  — the number of wise men in the city. The next $$$n$$$ lines contain a binary string of length $$$n$$$ each, such that the $$$j$$$-th character of the $$$i$$$-th string is equal to '1' if wise man $$$i$$$ knows wise man $$$j$$$, and equals '0' otherwise. It is guaranteed that if the $$$i$$$-th man knows the $$$j$$$-th man, then the $$$j$$$-th man knows $$$i$$$-th man and no man knows himself.


Let's call a graph with $$$n$$$ vertices, each of which has it's own point $$$A_i = (x_i, y_i)$$$ with integer coordinates, a planar tree if:  All points $$$A_1, A_2, \ldots, A_n$$$ are different and no three points lie on the same line.  The graph is a tree, i.e. there are exactly $$$n-1$$$ edges there exists a path between any pair of vertices.  For all pairs of edges $$$(s_1, f_1)$$$ and $$$(s_2, f_2)$$$, such that $$$s_1 \neq s_2, s_1 \neq f_2,$$$ $$$f_1 \neq s_2$$$, and $$$f_1 \neq f_2$$$, the segments $$$A_{s_1} A_{f_1}$$$ and $$$A_{s_2} A_{f_2}$$$ don't intersect. Imagine a planar tree with $$$n$$$ vertices. Consider the convex hull of points $$$A_1, A_2, \ldots, A_n$$$. Let's call this tree a spiderweb tree if for all $$$1 \leq i \leq n$$$ the following statements are true:  All leaves (vertices with degree $$$\leq 1$$$) of the tree lie on the border of the convex hull.  All vertices on the border of the convex hull are leaves. An example of a spiderweb tree:     The points $$$A_3, A_6, A_7, A_4$$$ lie on the convex hull and the leaf vertices of the tree are $$$3, 6, 7, 4$$$.Refer to the notes for more examples.Let's call the subset $$$S \subset \{1, 2, \ldots, n\}$$$ of vertices a subtree of the tree if for all pairs of vertices in $$$S$$$, there exists a path that contains only vertices from $$$S$$$. Note that any subtree of the planar tree is a planar tree.You are given a planar tree with $$$n$$$ vertexes. Let's call a partition of the set $$$\{1, 2, \ldots, n\}$$$ into non-empty subsets $$$A_1, A_2, \ldots, A_k$$$ (i.e. $$$A_i \cap A_j = \emptyset$$$ for all $$$1 \leq i < j \leq k$$$ and $$$A_1 \cup A_2 \cup \ldots \cup A_k = \{1, 2, \ldots, n\}$$$) good if for all $$$1 \leq i \leq k$$$, the subtree $$$A_i$$$ is a spiderweb tree. Two partitions are different if there exists some set that lies in one parition, but not the other.Find the number of good partitions. Since this number can be very large, find it modulo $$$998\,244\,353$$$.

The first line contains an integer $$$n$$$ ($$$1 \leq n \leq 100$$$) — the number of vertices in the tree. The next $$$n$$$ lines each contain two integers $$$x_i, y_i$$$ ($$$-10^9 \leq x_i, y_i \leq 10^9$$$)  — the coordinates of $$$i$$$-th vertex, $$$A_i$$$. The next $$$n-1$$$ lines contain two integers $$$s, f$$$ ($$$1 \leq s, f \leq n$$$) — the edges $$$(s, f)$$$ of the tree. It is guaranteed that all given points are different and that no three of them lie at the same line. Additionally, it is guaranteed that the given edges and coordinates of the points describe a planar tree.

Print one integer  — the number of good partitions of vertices of the given planar tree, modulo $$$998\,244\,353$$$.

Note    The picture for the first sample. In the first test case, all good partitions are:  $$$\{1\}$$$, $$$\{2\}$$$, $$$\{3\}$$$, $$$\{4\}$$$;  $$$\{1, 2\}$$$, $$$\{3\}$$$, $$$\{4\}$$$;  $$$\{1, 3\}$$$, $$$\{2\}$$$, $$$\{4\}$$$;  $$$\{1, 4\}$$$, $$$\{2\}$$$, $$$\{3\}$$$;  $$$\{1, 2, 3, 4\}$$$. The partition $$$\{1, 2, 3\}$$$, $$$\{4\}$$$ isn't good, because the subtree $$$\{1, 2, 3\}$$$ isn't spiderweb tree, since the non-leaf vertex $$$1$$$ lies on the convex hull.The partition $$$\{2, 3, 4\}$$$, $$$\{1\}$$$ isn't good, because the subset $$$\{2, 3, 4\}$$$ isn't a subtree.    The picture for the second sample. In the second test case, the given tree isn't a spiderweb tree, because the leaf vertex $$$1$$$ doesn't lie on the convex hull. However, the subtree $$$\{2, 3, 4, 5\}$$$ is a spiderweb tree.    The picture for the third sample.     The picture for the fourth sample. In the fourth test case, the partition $$$\{1, 2, 3, 4\}$$$, $$$\{5, 6, 7, 8\}$$$ is good because all subsets are spiderweb subtrees.


You are given two integers $$$n$$$ and $$$k$$$. Your task is to find if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers or not.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. The only line of the test case contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n, k \le 10^7$$$).

For each test case, print the answer — "YES" (without quotes) if $$$n$$$ can be represented as a sum of $$$k$$$ distinct positive odd (not divisible by $$$2$$$) integers and "NO" otherwise.

NoteIn the first test case, you can represent $$$3$$$ as $$$3$$$.In the second test case, the only way to represent $$$4$$$ is $$$1+3$$$.In the third test case, you cannot represent $$$10$$$ as the sum of three distinct positive odd integers.In the fourth test case, you can represent $$$10$$$ as $$$3+7$$$, for example.In the fifth test case, you can represent $$$16$$$ as $$$1+3+5+7$$$.In the sixth test case, you cannot represent $$$16$$$ as the sum of five distinct positive odd integers.


You are given a permutation, $$$p_1, p_2, \ldots, p_n$$$.Imagine that some positions of the permutation contain bombs, such that there exists at least one position without a bomb.For some fixed configuration of bombs, consider the following process. Initially, there is an empty set, $$$A$$$.For each $$$i$$$ from $$$1$$$ to $$$n$$$: Add $$$p_i$$$ to $$$A$$$.  If the $$$i$$$-th position contains a bomb, remove the largest element in $$$A$$$.After the process is completed, $$$A$$$ will be non-empty. The cost of the configuration of bombs equals the largest element in $$$A$$$.You are given another permutation, $$$q_1, q_2, \ldots, q_n$$$.For each $$$1 \leq i \leq n$$$, find the cost of a configuration of bombs such that there exists a bomb in positions $$$q_1, q_2, \ldots, q_{i-1}$$$. For example, for $$$i=1$$$, you need to find the cost of a configuration without bombs, and for $$$i=n$$$, you need to find the cost of a configuration with bombs in positions $$$q_1, q_2, \ldots, q_{n-1}$$$.

The first line contains a single integer, $$$n$$$ ($$$2 \leq n \leq 300\,000$$$). The second line contains $$$n$$$ distinct integers $$$p_1, p_2, \ldots, p_n$$$ ($$$1 \leq p_i \leq n)$$$. The third line contains $$$n$$$ distinct integers $$$q_1, q_2, \ldots, q_n$$$ ($$$1 \leq q_i \leq n)$$$.

Print $$$n$$$ space-separated integers, such that the $$$i$$$-th of them equals the cost of a configuration of bombs in positions $$$q_1, q_2, \ldots, q_{i-1}$$$.

NoteIn the first test:  If there are no bombs, $$$A$$$ is equal to $$$\{1, 2, 3\}$$$ at the end of the process, so the cost of the configuration is $$$3$$$.  If there is one bomb in position $$$1$$$, $$$A$$$ is equal to $$$\{1, 2\}$$$ at the end of the process, so the cost of the configuration is $$$2$$$;  If there are two bombs in positions $$$1$$$ and $$$2$$$, $$$A$$$ is equal to $$$\{1\}$$$ at the end of the process, so the cost of the configuration is $$$1$$$. In the second test:Let's consider the process for $$$i = 4$$$. There are three bombs on positions $$$q_1 = 5$$$, $$$q_2 = 2$$$, and $$$q_3 = 1$$$.At the beginning, $$$A = \{\}$$$.  Operation $$$1$$$: Add $$$p_1 = 2$$$ to $$$A$$$, so $$$A$$$ is equal to $$$\{2\}$$$. There exists a bomb in position $$$1$$$, so we should delete the largest element from $$$A$$$. $$$A$$$ is equal to $$$\{\}$$$.  Operation $$$2$$$: Add $$$p_2 = 3$$$ to $$$A$$$, so $$$A$$$ is equal to $$$\{3\}$$$. There exists a bomb in position $$$2$$$, so we should delete the largest element from $$$A$$$. $$$A$$$ is equal to $$$\{\}$$$.  Operation $$$3$$$: Add $$$p_3 = 6$$$ to $$$A$$$, so $$$A$$$ is equal to $$$\{6\}$$$. There is no bomb in position $$$3$$$, so we do nothing.  Operation $$$4$$$: Add $$$p_4 = 1$$$ to $$$A$$$, so $$$A$$$ is equal to $$$\{1, 6\}$$$. There is no bomb in position $$$4$$$, so we do nothing.  Operation $$$5$$$: Add $$$p_5 = 5$$$ to $$$A$$$, so $$$A$$$ is equal to $$$\{1, 5, 6\}$$$. There exists a bomb in position $$$5$$$, so we delete the largest element from $$$A$$$. Now, $$$A$$$ is equal to $$$\{1, 5\}$$$.  Operation $$$6$$$: Add $$$p_6 = 4$$$ to $$$A$$$, so $$$A$$$ is equal to $$$\{1, 4, 5\}$$$. There is no bomb in position $$$6$$$, so we do nothing. In the end, we have $$$A = \{1, 4, 5\}$$$, so the cost of the configuration is equal to $$$5$$$.


You are given a colored permutation $$$p_1, p_2, \dots, p_n$$$. The $$$i$$$-th element of the permutation has color $$$c_i$$$.Let's define an infinite path as infinite sequence $$$i, p[i], p[p[i]], p[p[p[i]]] \dots$$$ where all elements have same color ($$$c[i] = c[p[i]] = c[p[p[i]]] = \dots$$$).We can also define a multiplication of permutations $$$a$$$ and $$$b$$$ as permutation $$$c = a \times b$$$ where $$$c[i] = b[a[i]]$$$. Moreover, we can define a power $$$k$$$ of permutation $$$p$$$ as $$$p^k=\underbrace{p \times p \times \dots \times p}_{k \text{ times}}$$$.Find the minimum $$$k > 0$$$ such that $$$p^k$$$ has at least one infinite path (i.e. there is a position $$$i$$$ in $$$p^k$$$ such that the sequence starting from $$$i$$$ is an infinite path).It can be proved that the answer always exists.

The first line contains single integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of test cases. Next $$$3T$$$ lines contain test cases — one per three lines. The first line contains single integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the permutation. The second line contains $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$ ($$$1 \le p_i \le n$$$, $$$p_i \neq p_j$$$ for $$$i \neq j$$$) — the permutation $$$p$$$. The third line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$1 \le c_i \le n$$$) — the colors of elements of the permutation. It is guaranteed that the total sum of $$$n$$$ doesn't exceed $$$2 \cdot 10^5$$$.

Print $$$T$$$ integers — one per test case. For each test case print minimum $$$k > 0$$$ such that $$$p^k$$$ has at least one infinite path.

NoteIn the first test case, $$$p^1 = p = [1, 3, 4, 2]$$$ and the sequence starting from $$$1$$$: $$$1, p[1] = 1, \dots$$$ is an infinite path.In the second test case, $$$p^5 = [1, 2, 3, 4, 5]$$$ and it obviously contains several infinite paths.In the third test case, $$$p^2 = [3, 6, 1, 8, 7, 2, 5, 4]$$$ and the sequence starting from $$$4$$$: $$$4, p^2[4]=8, p^2[8]=4, \dots$$$ is an infinite path since $$$c_4 = c_8 = 4$$$.


You wrote down all integers from $$$0$$$ to $$$10^n - 1$$$, padding them with leading zeroes so their lengths are exactly $$$n$$$. For example, if $$$n = 3$$$ then you wrote out 000, 001, ..., 998, 999.A block in an integer $$$x$$$ is a consecutive segment of equal digits that cannot be extended to the left or to the right.For example, in the integer $$$00027734000$$$ there are three blocks of length $$$1$$$, one block of length $$$2$$$ and two blocks of length $$$3$$$.For all integers $$$i$$$ from $$$1$$$ to $$$n$$$ count the number of blocks of length $$$i$$$ among the written down integers.Since these integers may be too large, print them modulo $$$998244353$$$.

The only line contains one integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$).

In the only line print $$$n$$$ integers. The $$$i$$$-th integer is equal to the number of blocks of length $$$i$$$. Since these integers may be too large, print them modulo $$$998244353$$$.