Codeforces Round 1065 (Div. 3)
A. Shizuku Hoshikawa and Farm Legs
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Nothing's ever been the same since... that summer with her.
— Shizuku Hoshikawa

Kaori wants to spend the day with Shizuku! However, the zoo is closed, so they are visiting Farmer John's farm instead.

At Farmer John's farm, Shizuku counts $$$n$$$ legs. It is known that only chickens and cows live on the farm; a chicken has $$$2$$$ legs, while a cow has $$$4$$$.

Count how many different configurations of Farmer John's farm are possible. Two configurations are considered different if they contain either a different number of chickens, a different number of cows, or both.

Note that Farmer John's farm may contain zero chickens or zero cows.

Input

The first line contains a single integer $$$t$$$ ($$$1 \leq t \leq 100$$$)  — the number of test cases.

The only line of each test case contains a single integer $$$n$$$ ($$$1\leq n \leq 100$$$).

Output

For each test case, output a single integer, the number of different configurations of Farmer John's farm that are possible.

Example
Input
5
2
3
4
6
100
Output
1
0
2
2
26
Note

For $$$n=4$$$, there are two possible configurations of Farmer John's farm:

  • he can have two chickens and zero cows, or
  • he can have zero chickens and one cow.
It can be shown that these are the only possible configurations of Farmer John's farm.

For $$$n=3$$$, it can be shown that there are no possible configurations of Farmer John's farm.

B. Yuu Koito and Minimum Absolute Sum
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The words in shoujo manga and love songs... they're always sparkling brightly. I don't need a dictionary to understand the meaning... but I've never felt them for myself.
— Yuu Koito

Yuu is trying out the student council! Unfortunately, she is being forced to do clerical work... Touko wants her to fill out the blanks in various student council documents.

You are given a partially filled array of nonnegative integers $$$a_1, a_2, \dots, a_n$$$, where blank elements are denoted with $$$-1$$$. You would like to fill in the blank elements with nonnegative integers, such that the absolute value of the sum of the elements in its difference array is minimized.

More formally, let $$$b$$$ be the array of length $$$n-1$$$ such that $$$b_i = a_{i+1} - a_i$$$ for all $$$1\leq i\leq n-1$$$. Find the minimum possible value of $$$|b_1 + b_2 + \dots + b_{n-1}|$$$, across all possible ways to fill in the blank elements of $$$a$$$.

Additionally, output the array that achieves this minimum. If there are multiple such arrays, output the one that is lexicographically smallest$$$^{\text{∗}}$$$.

$$$^{\text{∗}}$$$For two arbitrary arrays $$$c$$$ and $$$d$$$ of length $$$n$$$, we say that $$$c$$$ is lexicographically smaller than $$$d$$$ if there exists an index $$$i$$$ ($$$1\leq i\leq n$$$) such that $$$c_j = d_j$$$ for all $$$j \lt i$$$, and $$$c_i \lt d_i$$$. In other words, $$$c$$$ and $$$d$$$ differ in at least one index, and at the first index at which they differ, $$$c_i$$$ is smaller than $$$d_i$$$.

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers, $$$a_1, a_2, \dots, a_n$$$ ($$$-1\leq a_i \leq 10^6$$$).

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

Output

For each test case, on the first line, output the minimum possible value of $$$|b_1 + b_2 + \dots + b_{n-1}|$$$. Then, on the second line, output $$$n$$$ integers, the values of $$$a_1, a_2, \dots, a_n$$$ in the lexicographically smallest array achieving this minimum.

Example
Input
6
4
2 -1 7 1
4
-1 2 4 -1
8
2 -1 1 5 11 12 1 -1
3
-1 -1 -1
3
2 5 4
2
-1 5
Output
1
2 0 7 1
0
0 2 4 0
0
2 0 1 5 11 12 1 2
0
0 0 0
2
2 5 4
0
5 5
Note

In the first example, we fill in the array $$$a = [2, 0, 7, 1]$$$, which yields the difference array $$$b = [-2, 7, -6]$$$.

The absolute value of the sum of the elements in $$$b$$$ is $$$1$$$. It can be proven that this is the minimum possible. Furthermore, it can be proven that this is the lexicographically smallest array $$$a$$$ that achieves this minimum.

C1. Renako Amaori and XOR Game (easy version)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Yup. I couldn't do this any longer. No. Freaking. Way.
— Renako Amaori

This is the easy version of the problem. The only difference between the easy and hard versions is that in the easy version, $$$a_i, b_i \leq 1$$$.

Renako is stuck between a rock and a hard place... and by that, of course, I mean Ajisai and Mai! Both of them want to hang out with her, and she just can't decide! So Ajisai and Mai have decided to play the XOR game.

Ajisai and Mai are given arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ ($$$0\leq a_i, b_i\leq {\color{red}{1}}$$$). They will play a game that lasts for $$$n$$$ turns, where Ajisai moves on odd-numbered turns and Mai moves on even-numbered turns. On the $$$i$$$-th turn, the player to move may choose to swap $$$a_i$$$ and $$$b_i$$$, or pass.

Note that if a swap occurs, the index that is being swapped must match the turn number. For example, on the first turn, Ajisai may choose to swap $$$a_1$$$ and $$$b_1$$$, or pass. On the second turn, Mai may choose to swap $$$a_2$$$ and $$$b_2$$$, or pass. This continues for $$$n$$$ turns. Thus, only Ajisai can swap odd indices, and only Mai can swap even indices.

At the end of the game, Ajisai achieves a score of $$$a_1 \oplus a_2 \oplus \dots \oplus a_n$$$, and Mai achieves a score of $$$b_1 \oplus b_2 \oplus \dots \oplus b_n$$$$$$^{\text{∗}}$$$. The player with the higher score wins. If the players have the same score, the game ends in a tie.

Determine the outcome of the game with optimal play. More formally, one player is considered to win with optimal play if there exists a strategy for them such that they always win, regardless of their opponent's choices. The game is considered a tie with optimal play if neither player has such a strategy.

$$$^{\text{∗}}$$$$$$\oplus$$$ denotes the bitwise XOR operation

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$1\leq n\leq 2\cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers, $$$a_1, a_2, \dots, a_n$$$ ($$$0\leq a_i\leq 1$$$).

The third line of each test case contains $$$n$$$ integers, $$$b_1, b_2, \dots, b_n$$$ ($$$0\leq b_i\leq 1$$$).

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

Output

For each test case, output on a single line "Ajisai" if Ajisai wins with optimal play, "Mai" if Mai wins with optimal play, or "Tie" if the game ends in a tie with optimal play.

You may output the answer in any case (upper or lower). For example, the strings "mAi", "mai", "MAI", and "maI" will be recognized as "Mai".

Example
Input
6
4
1 0 0 1
1 0 1 1
6
0 1 1 1 1 0
0 0 1 0 1 1
4
0 0 1 0
1 0 1 1
5
1 0 1 1 1
0 1 1 1 0
6
1 1 1 1 1 1
1 1 1 1 1 1
5
0 1 0 0 1
1 0 0 1 1
Output
Ajisai
Mai
Tie
Ajisai
Tie
Mai
Note

In the first example, one way the game might play out is as follows:

On turn 1, Ajisai chooses to swap $$$a_1$$$ and $$$b_1$$$. Now the arrays are $$$a = [1, 0, 0, 1]$$$ and $$$b = [1, 0, 1, 1]$$$.

On turn 2, Mai chooses to pass.

On turn 3, Ajisai chooses to swap $$$a_3$$$ and $$$b_3$$$. Now the arrays are $$$a = [1, 0, 1, 1]$$$ and $$$b = [1, 0, 0, 1]$$$.

On turn 4, Mai chooses to swap $$$a_4$$$ and $$$b_4$$$. Now the arrays are $$$a = [1, 0, 1, 1]$$$ and $$$b = [1, 0, 0, 1]$$$.

Now, Ajisai's final score is $$$1\oplus 0\oplus 1\oplus 1 = 1$$$ and Mai's final score is $$$1\oplus 0\oplus 0\oplus 1 = 0$$$. Therefore, Ajisai wins the game.

It is not guaranteed that the above description is representative of optimal play.

C2. Renako Amaori and XOR Game (hard version)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Yup. I couldn't do this any longer. No. Freaking. Way.
— Renako Amaori

This is the hard version of the problem. The only difference between the easy and hard versions is that in the hard version, $$$a_i, b_i \leq 10^6$$$.

Renako is stuck between a rock and a hard place... and by that, of course, I mean Ajisai and Mai! Both of them want to hang out with her, and she just can't decide! So Ajisai and Mai have decided to play the XOR game.

Ajisai and Mai are given arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ ($$$0\leq a_i, b_i\leq {\color{red}{10^6}}$$$). They will play a game that lasts for $$$n$$$ turns, where Ajisai moves on odd-numbered turns and Mai moves on even-numbered turns. On the $$$i$$$-th turn, the player to move may choose to swap $$$a_i$$$ and $$$b_i$$$, or pass.

Note that if a swap occurs, the index that is being swapped must match the turn number. For example, on the first turn, Ajisai may choose to swap $$$a_1$$$ and $$$b_1$$$, or pass. On the second turn, Mai may choose to swap $$$a_2$$$ and $$$b_2$$$, or pass. This continues for $$$n$$$ turns. Thus, only Ajisai can swap odd indices, and only Mai can swap even indices.

At the end of the game, Ajisai achieves a score of $$$a_1 \oplus a_2 \oplus \dots \oplus a_n$$$, and Mai achieves a score of $$$b_1 \oplus b_2 \oplus \dots \oplus b_n$$$$$$^{\text{∗}}$$$. The player with the higher score wins. If the players have the same score, the game ends in a tie.

Determine the outcome of the game with optimal play. More formally, one player is considered to win with optimal play if there exists a strategy for them such that they always win, regardless of their opponent's choices. The game is considered a tie with optimal play if neither player has such a strategy.

$$$^{\text{∗}}$$$$$$\oplus$$$ denotes the bitwise XOR operation

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$1\leq n\leq 2\cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers, $$$a_1, a_2, \dots, a_n$$$ ($$$0\leq a_i\leq 10^6$$$).

The third line of each test case contains $$$n$$$ integers, $$$b_1, b_2, \dots, b_n$$$ ($$$0\leq b_i\leq 10^6$$$).

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

Output

For each test case, output on a single line "Ajisai" if Ajisai wins with optimal play, "Mai" if Mai wins with optimal play, or "Tie" if the game ends in a tie with optimal play.

You may output the answer in any case (upper or lower). For example, the strings "mAi", "mai", "MAI", and "maI" will be recognized as "Mai".

Example
Input
6
4
1 4 6 1
3 2 3 7
6
20 11 1 7 7 0
14 8 3 6 17 6
4
2 6 3 6
3 4 7 1
5
1 4 5 5 3
6 7 1 2 13
6
9 5 9 17 17 6
1 13 6 13 1 15
5
2 3 8 1 5
3 1 6 14 7
Output
Mai
Ajisai
Tie
Ajisai
Mai
Tie
Note

In the first example, one way the game might play out is as follows:

On turn 1, Ajisai chooses to swap $$$a_1$$$ and $$$b_1$$$. Now the arrays are $$$a = [3, 4, 6, 1]$$$ and $$$b = [1, 2, 3, 7]$$$.

On turn 2, Mai chooses to swap $$$a_2$$$ and $$$b_2$$$. Now the arrays are $$$a = [3, 2, 6, 1]$$$ and $$$b = [1, 4, 3, 7]$$$.

On turn 3, Ajisai chooses to pass.

On turn 4, Mai chooses to swap $$$a_4$$$ and $$$b_4$$$. Now the arrays are $$$a = [3, 2, 6, 7]$$$ and $$$b = [1, 4, 3, 1]$$$.

Now, Ajisai's final score is $$$3\oplus 2\oplus 6\oplus 7 = 0$$$ and Mai's final score is $$$1\oplus 4\oplus 3\oplus 1 = 7$$$. Therefore, Mai wins the game.

It is not guaranteed that the above description is representative of optimal play.

For additional examples, see the examples of the easy version.

D. Rae Taylor and Trees (easy version)
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
"To think a commoner would even fathom sitting next to me. Know your place!"
— Claire François

This is the easy version of the problem. The only difference between the easy and hard versions is that the hard version asks you to construct an example of a satisfactory tree.

As an Earth mage, Rae has mastered the spell of growing trees! But Manaria brags that she can grow a more impressive species of trees. Rae remembers that the most rare type of tree can be grown using a formula represented by a certain permutation — please help her construct it!

You are given a permutation$$$^{\text{∗}}$$$ $$$p$$$ of length $$$n$$$.

Determine if there exists an undirected tree with $$$n$$$ vertices labeled $$$1, 2, \dots, n$$$, satisfying the following condition:

  • Let $$$u$$$ and $$$v$$$ ($$$1\leq {\color{red}{u \lt v}} \leq n$$$) be any two vertices connected by an edge. Then $$$u$$$ appears before $$$v$$$ in $$$p$$$.

$$$^{\text{∗}}$$$A permutation of length $$$n$$$ is an array that contains every integer from $$$1$$$ to $$$n$$$ exactly once, in any order.

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers, $$$p_1, p_2, \dots, p_n$$$ ($$$1\leq p_i\leq n$$$). It is guaranteed that all $$$p_i$$$ are distinct.

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

Output

For each test case, output on a single line "Yes" if there exists a tree satisfying the given condition, and "No" otherwise.

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

Example
Input
9
6
1 3 4 5 2 6
4
3 4 1 2
5
4 3 5 1 2
4
1 2 3 4
7
4 3 5 7 6 2 1
6
2 4 6 1 3 5
3
2 1 3
4
2 4 1 3
6
4 2 6 5 1 3
Output
Yes
No
No
Yes
No
Yes
Yes
Yes
Yes
Note

In the first example, we can construct the tree with the following edges:

  • $$$\{3, 1\}$$$,
  • $$$\{4, 1\}$$$,
  • $$$\{6, 5\}$$$,
  • $$$\{6, 2\}$$$,
  • $$$\{6, 1\}$$$.

Then we have that

  • $$$1 \lt 3$$$, and $$$1$$$ appears before $$$3$$$ in $$$p$$$,
  • $$$1 \lt 4$$$, and $$$1$$$ appears before $$$4$$$ in $$$p$$$,
  • $$$5 \lt 6$$$, and $$$5$$$ appears before $$$6$$$ in $$$p$$$,
  • $$$2 \lt 6$$$, and $$$2$$$ appears before $$$6$$$ in $$$p$$$,
  • $$$1 \lt 6$$$, and $$$1$$$ appears before $$$6$$$ in $$$p$$$.

In the second example, it can be shown that there does not exist a tree satisfying the given constraints.

E. Anisphia Wynn Palettia and Good Permutations
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
I've always loved the word magic. It has a way of making people happy, of putting a smile on their faces.
— Anisphia Wynn Palettia

Anis and her new assistant Euphie are improving the Witch's Broom! Magicology requires great precision and care — in order to fly, the construction of the broom must have sufficiently few imperfections.

For an arbitrary array $$$a$$$ of length $$$m$$$, call an index $$$i$$$ ($$$1\leq i\leq m-2$$$) bad if $$$a_i$$$, $$$a_{i+1}$$$, and $$$a_{i+2}$$$ are all pairwise coprime. More formally, $$$i$$$ is a bad index if and only if $$$\gcd(a_i, a_{i+1}) = \gcd(a_i, a_{i+2}) = \gcd(a_{i+1}, a_{i+2}) = 1$$$$$$^{\text{∗}}$$$. Furthermore, call $$$a$$$ good if it has at most $$$6$$$ bad indices.

You are given an integer $$$n$$$. Construct a good permutation$$$^{\text{†}}$$$ $$$p$$$ of length $$$n$$$. It can be shown that such a permutation always exists.

Note that you do not have to minimize the number of bad indices.

$$$^{\text{∗}}$$$$$$\gcd(x, y)$$$ denotes the greatest common divisor of $$$x$$$ and $$$y$$$

$$$^{\text{†}}$$$ A permutation of length $$$n$$$ is an array that contains every integer from $$$1$$$ to $$$n$$$ exactly once, in any order.

Input

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

The only line of each test case contains a single integer $$$n$$$ ($$$3\leq n \leq 2\cdot 10^5$$$).

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

Output

For each test case, output on a single line $$$n$$$ integers $$$p_1, p_2, \dots, p_n$$$, an example of a good permutation of length $$$n$$$. If there are multiple good permutations, you may output any of them.

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

For $$$n=9$$$, we have

$$$i$$$$$$p_i$$$$$$p_{i+1}$$$$$$p_{i+2}$$$$$$\gcd(p_i, p_{i+1})$$$$$$\gcd(p_i, p_{i+2})$$$$$$\gcd(p_{i+1}, p_{i+2})$$$
$$$1$$$$$$5$$$$$$4$$$$$$8$$$$$$1$$$$$$1$$$$$$4$$$
$$$2$$$$$$4$$$$$$8$$$$$$1$$$$$$4$$$$$$1$$$$$$1$$$
$$$3$$$$$$8$$$$$$1$$$$$$9$$$$$$1$$$$$$1$$$$$$1$$$
$$$4$$$$$$1$$$$$$9$$$$$$3$$$$$$1$$$$$$1$$$$$$3$$$
$$$5$$$$$$9$$$$$$3$$$$$$6$$$$$$3$$$$$$3$$$$$$3$$$
$$$6$$$$$$3$$$$$$6$$$$$$2$$$$$$3$$$$$$1$$$$$$2$$$
$$$7$$$$$$6$$$$$$2$$$$$$7$$$$$$2$$$$$$1$$$$$$1$$$

The only bad index is $$$3$$$. Since $$$1\leq 6$$$, $$$p$$$ is a good permutation.

F. Rae Taylor and Trees (hard version)
time limit per test
3 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
"To think a commoner would even fathom sitting next to me. Know your place!"
— Claire François

This is the hard version of the problem. The only difference between the easy and hard versions is that the hard version asks you to construct an example of a satisfactory tree.

As an Earth mage, Rae has mastered the spell of growing trees! But Manaria brags that she can grow a more impressive species of trees. Rae remembers that the most rare type of tree can be grown using a formula represented by a certain permutation — please help her construct it!

You are given a permutation$$$^{\text{∗}}$$$ $$$p$$$ of length $$$n$$$.

Determine if there exists an undirected tree with $$$n$$$ vertices labeled $$$1, 2, \dots, n$$$, satisfying the following condition:

  • Let $$$u$$$ and $$$v$$$ ($$$1\leq {\color{red}{u \lt v}} \leq n$$$) be any two vertices connected by an edge. Then $$$u$$$ appears before $$$v$$$ in $$$p$$$.

Additionally, if there exists such a tree, output any of them.

$$$^{\text{∗}}$$$A permutation of length $$$n$$$ is an array that contains every integer from $$$1$$$ to $$$n$$$ exactly once, in any order.

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers, $$$p_1, p_2, \dots, p_n$$$ ($$$1\leq p_i\leq n$$$). It is guaranteed that all $$$p_i$$$ are distinct.

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

Output

For each test case, output on a single line "Yes" if there exists a tree satisfying the given condition, and "No" otherwise.

Then, if the answer is "Yes", output $$$n-1$$$ lines. The $$$i$$$-th of these lines should contain two integers $$$u$$$ and $$$v$$$, denoting an edge connecting vertices $$$u$$$ and $$$v$$$.

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

Example
Input
9
6
1 3 4 5 2 6
4
3 4 1 2
5
4 3 5 1 2
4
1 2 3 4
7
4 3 5 7 6 2 1
6
2 4 6 1 3 5
3
2 1 3
4
2 4 1 3
6
4 2 6 5 1 3
Output
Yes
3 1
4 1
6 5
6 2
6 1
No
No
Yes
2 1
4 3
4 1
No
Yes
4 2
6 2
3 1
5 1
5 2
Yes
3 2
3 1
Yes
4 2
3 1
3 2
Yes
6 4
6 2
3 1
5 4
2 3
Note

In the first example, we can construct the tree given in the sample output. We have that

  • $$$1 \lt 3$$$, and $$$1$$$ appears before $$$3$$$ in $$$p$$$,
  • $$$1 \lt 4$$$, and $$$1$$$ appears before $$$4$$$ in $$$p$$$,
  • $$$5 \lt 6$$$, and $$$5$$$ appears before $$$6$$$ in $$$p$$$,
  • $$$2 \lt 6$$$, and $$$2$$$ appears before $$$6$$$ in $$$p$$$,
  • $$$1 \lt 6$$$, and $$$1$$$ appears before $$$6$$$ in $$$p$$$.

In the second example, it can be shown that there does not exist a tree satisfying the given constraints.

G. Sakura Adachi and Optimal Sequences
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
"What a pain..."
— Hougetsu Shimamura

Adachi is in the middle of a generational crashout... over, uh, this problem! Yep, that's definitely it... anyways, please help her solve it!

You are given two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ ($$$1\leq a_i\leq b_i$$$).

In one operation, you may either:

  • choose an index $$$i$$$ ($$$1\leq i\leq n$$$) and set $$$a_i := a_i + 1$$$, or
  • double all elements of $$$a$$$.

Let $$$x$$$ denote the minimum number of operations needed to make $$$a = b$$$. Two arrays $$$a$$$ and $$$b$$$ of length $$$n$$$ are considered equal if $$$a_i = b_i$$$ for all $$$1\leq i\leq n$$$.

Find the value of $$$x$$$. Additionally, count the number of sequences of operations that make $$$a = b$$$ using exactly $$$x$$$ operations. Two such sequences of operations are considered different if, for any $$$1\leq j\leq x$$$, the $$$j$$$-th operation of each sequence differs (either in the type of operation selected or the index chosen, if applicable).

Since the number of sequences may be large, output it modulo $$${\color{red}{10^6+3}}$$$. Note that $$$10^6+3$$$ is a prime number.

Input

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

The first line of each test case contains a single integer $$$n$$$ ($$$2\leq n\leq 2\cdot 10^5$$$).

The second line of each test case contains $$$n$$$ integers, $$$a_1, a_2, \dots, a_n$$$ ($$$1\leq a_i\leq 10^6$$$).

The third line of each test case contains $$$n$$$ integers, $$$b_1, b_2, \dots, b_n$$$ ($$$a_i\leq b_i\leq 10^6$$$).

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

Output

For each test case, output two integers, the value of $$$x$$$, and the number of sequences of operations that make $$$a = b$$$ using exactly $$$x$$$ operations, modulo $$$10^6+3$$$. The value of $$$x$$$ should be printed exactly; that is, it should not be taken modulo $$$10^6 + 3$$$.

Example
Input
8
6
1 3 6 4 3 2
3 7 10 4 4 8
2
1 1
4 3
5
2 3 2 5 1
18 13 10 30 7
5
5 4 3 6 2
100 125 231 113 107
4
2 2 2 2
2 2 2 2
4
1 1 1 1
2 2 2 2
7
1 1 1 1 1 1 200000
200000 200000 200000 200000 200000 200000 200000
3
542264 174876 441510
641112 325241 995342
Output
17 827116
3 1
12 288
35 567812
0 1
1 1
1199994 0
803045 366998
Note

In the second sample, it is possible to convert $$$a$$$ into $$$b$$$ using only three operations. There is only one way to do so, namely:

  • Add $$$1$$$ to $$$a_1$$$, yielding $$$a = [2, 1]$$$. Then double all elements of $$$a$$$, yielding $$$a = [4, 2]$$$. Then add $$$1$$$ to $$$a_2$$$, yielding $$$a = [4, 3]$$$. Then we have that $$$a = b$$$, as desired.

It can be shown that it is impossible to convert $$$a$$$ into $$$b$$$ using fewer than three operations.

H. Shiori Miyagi and Maximum Array Score
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
"Are you stupid, Sendai-san?"
— Shiori Miyagi

For the cost of 5000 yen, Miyagi can ask Sendai to do whatever she wants! Today, Miyagi demands that Sendai make her an array... specifically, Miyagi only wants a very particular type of array.

For arbitrary integers $$$b\geq 2$$$ and $$$x\geq 1$$$, define $$$v(b, x)$$$ to be the maximal $$$k$$$ satisfying $$$b^k \mid x$$$; that is, the maximal $$$k$$$ such that $$$x$$$ is a multiple of $$$b^k$$$. It can be shown that this is always a well-defined, nonnegative integer.

You are given integers $$$n$$$ and $$$m$$$ satisfying $$$n\leq m$$$. Find the maximum value of $$$\sum_{i=2}^n v(i, a_i)$$$ across all arrays $$$a$$$ of length $$$n$$$ satisfying the following conditions:

  • $$$a$$$ is strictly increasing; that is, for all $$$1\leq i\leq n-1$$$, $$$a_i \lt a_{i+1}$$$, and
  • for all $$$1\leq i\leq n$$$, $$$1\leq a_i\leq m$$$.
Input

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

The only line of each test case contains two integers $$$n$$$ and $$$m$$$ ($$$2\leq n\leq m \leq 2\cdot 10^5$$$).

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

Output

For each test case, output a single integer, the maximum value of $$$\sum_{i=2}^n v(i, a_i)$$$ across all arrays $$$a$$$ of length $$$n$$$ satisfying the given conditions.

Example
Input
6
4 20
6 6
6 216
3 500
2 8
5 29
Output
7
5
19
13
3
9
Note

In the first example, one possible array is $$$a = [6, 8, 9, 16]$$$ which yields a value of $$$3 + 2 + 2 = 7$$$.

It can be shown that this is the maximum value of $$$\sum_{i=2}^n v(i, a_i)$$$ across all arrays $$$a$$$ of length $$$n$$$ satisfying the given conditions.