PSUT Marathon 2026
A. Meow loves mEow loves meOw (4 Version) (Red)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Michelangelo has adopted $$$N$$$ mutant cats and arranged them in a circle ($$$N$$$ is a multiple of 4).

He needs to assign each cat a letter from the set [$$$m$$$, $$$e$$$, $$$o$$$, $$$w$$$, $$$M$$$, $$$E$$$, $$$O$$$, $$$W$$$] to form a continuous circular string.

The string must follow Master Splinter's strict training rules:

  1. The Base: It must be made of continuous 4-letter "meow" blocks (case-insensitive);
  2. The Capital: In every block, exactly one letter is capitalized;
  3. The Shift: The capital letter shifts exactly 1 position to the right in each following block.(For example: Meow $$$\to$$$ mEow $$$\to$$$ meOw $$$\to$$$ meoW $$$\to$$$ Meow...).

You are also given $$$M$$$ constraints. Each constraint is a pair of numbers $$$(u, v)$$$, meaning the cat at index $$$u$$$ and the cat at index $$$v$$$ must be assigned the exact same character (both the letter and the case must match perfectly).

Calculate the total number of valid circular strings you can create that satisfy all the rules and all $$$M$$$ constraints.

Input

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

for each test case:

The first line is Two space-separated integers $$$N$$$ ($$$4 \le N \le 10^5$$$) and $$$M$$$ ($$$0 \le M \le 10^5$$$) — denotes the number of cats and it is guaranteed to be a multiple of 4, and the number of constraints respectively.

The next $$$M$$$ lines contains Two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le N$$$) — denotes a constraint where the character at position $$$u$$$ must equal the character at position $$$v$$$.

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

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

Output

For each test case print the total number of valid circular strings.

Example
Input
5
16 1
1 13
16 1
2 10
32 3
16 20
18 6
24 24
20 2
1 5
2 6
48 3
4 20
12 28
16 32
Output
8
8
2
0
16

B. Rayo loves DNA Repair (Orange)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Raphael and Rayo are trying to fix a corrupted genetic sequence for the team!

They have an initial DNA string $$$a$$$ and a target DNA string $$$b$$$.

To transform string $$$a$$$ into string $$$b$$$, they must use the following techniques:

  • The Ninja Shadow Swap: Raphael has mastered certain connection points $$$(i, j)$$$ in the DNA. He can swap the characters at these positions in string $$$a$$$ as many times as he wants for free (0 operations);
  • The Katana Strike (Replacement): If a character cannot be moved into the correct spot via swaps, Raphael must use his katana to slice out the old character and replace it with a new one of his choice, Each replacement costs 1 operation.
Trying to figure it out

Find the minimum number of replacement operations needed to make string $$$a$$$ match string $$$b$$$. If the transformation is impossible, print -1.

Input

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

for each test case:

The first line is two strings $$$a$$$ and $$$b$$$ ($$$1 \le |a| , |b| \le 10^5$$$) — denotes the starting DNA and the target DNA, they are guaranteed to only have lowercase letters.

The second line is an integer $$$M$$$ — denotes the number of pairs that can be swapped for free.

The next $$$M$$$ lines contains two integers $$$i$$$ and $$$j$$$ ($$$1 \le i, j \le |a|$$$) — denotes the positions in string $$$a$$$ that can be swapped for free.

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

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

Output

for each test case, print a single integer, the minimum number of replacement operations needed.

If it's impossible, print -1.

Example
Input
3
turtle purtel
2
1 6
4 5
abc def
0
hello world
1
1 2
Output
3
3
4

C. Meow loves mEow loves meOw (8 Version) (Yellow)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Michelangelo has adopted $$$N$$$ mutant cats and arranged them in a circle ($$$N$$$ is a multiple of 8).

He needs to assign each cat a letter from the set [$$$m$$$, $$$e$$$, $$$o$$$, $$$w$$$, $$$M$$$, $$$E$$$, $$$O$$$, $$$W$$$] to form a continuous circular string.

The string must follow Master Splinter's strict training rules:

  1. The Base: It must be made of continuous 4-letter "meow" blocks (case-insensitive);
  2. The Capital: In every block, exactly one letter is capitalized;
  3. The Shift: The capital letter must shift exactly 1 position to the left OR 1 position to the right in the following block. (For example: if the current block is mEow, the next block must be either Meow or meOw).

You are also given $$$M$$$ constraints. Each constraint is a pair of numbers $$$(u, v)$$$, meaning the cat at index $$$u$$$ and the cat at index $$$v$$$ must be assigned the exact same character (both the letter and the case must match perfectly).

Calculate the total number of valid circular strings you can create that satisfy all the rules and all $$$M$$$ constraints.

Since the answer can be very large, output it modulo $$$10^9 + 7$$$.

Input

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

for each test case:

The first line is Two space-separated integers $$$N$$$ ($$$8 \le N \le 10^5$$$) and $$$M$$$ ($$$0 \le M \le 10^5$$$) — denotes the number of cats and it is guaranteed to be a multiple of 8, and the number of constraints respectively.

The next $$$M$$$ lines: Two space-separated integers $$$u$$$ and $$$v$$$ ($$$1 \le u, v \le N$$$) — denotes a constraint where the character at position $$$u$$$ must equal the character at position $$$v$$$.

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

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

Output

For each test case, print the total number of valid circular strings modulo $$$10^9 + 7$$$.

Example
Input
3
8 0
8 1
2 6
8 1
1 6
Output
8
4
0

D. Rafael Leão (Light Blue)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Leonardo and Raphael are chasing Shredder through a long underground sewer.

The sewer consists of $$$n$$$ chambers arranged in a straight line, numbered from $$$1$$$ to $$$n$$$ from left to right.

At the beginning, Shredder may be anywhere in the sewer. Leonardo blocks the left side at chamber $$$L = 1$$$, and Raphael blocks the right side at chamber $$$R = n$$$. Therefore, the possible area where Shredder can still be hiding is the segment $$$[L, R]$$$.

no comment.

The turtles want to shrink this segment as much as possible.

You are given four arrays $$$a$$$, $$$b$$$, $$$c$$$, and $$$d$$$.

For every chamber $$$i$$$, the following conditions hold:

$$$$$$c_i \ge a_i \ge i$$$$$$

and

$$$$$$d_i \le b_i \le i$$$$$$

The turtles can perform the following moves any number of times and in any order:

  • If Leonardo is currently at chamber $$$L$$$, he may move forward to chamber $$$a_L$$$.

    However, this move is only safe if Raphael is far enough to cover him. Formally, the move is allowed only if:

    $$$$$$R \ge c_L$$$$$$

    After the move, the left boundary becomes $$$L = a_L$$$.

  • If Raphael is currently at chamber $$$R$$$, he may move backward to chamber $$$b_R$$$.

    However, this move is only safe if Leonardo is far enough to cover him. Formally, the move is allowed only if:

    $$$$$$L \le d_R$$$$$$

    After the move, the right boundary becomes $$$R = b_R$$$.

The turtles may stop after any number of moves. Their goal is to minimize the size of the final possible hiding segment.

Find the minimum possible value of:

$$$$$$R - L + 1$$$$$$

Input

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

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

The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$i \le a_i \le n$$$) — denotes the target chamber Leo can move to from chamber $$$i$$$.

The third line contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$1 \le b_i \le i$$$) — denotes the target chamber Raph can move to from chamber $$$i$$$.

The fourth line contains $$$n$$$ integers $$$c_1, c_2, \dots, c_n$$$ ($$$a_i \le c_i \le n$$$) — denotes the minimum chamber position Raph must be at ($$$R \ge c_L$$$) for Leo to safely execute his move from chamber $$$L$$$.

The fifth line contains $$$n$$$ integers $$$d_1, d_2, \dots, d_n$$$ ($$$1 \le d_i \le b_i$$$) — denotes the maximum chamber position Leo can be at ($$$L \le d_R$$$) for Raph to safely execute his move from chamber $$$R$$$.

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

Output

For each test case, print a single integer — the minimum possible size of the final segment where Shredder may still be hiding.

Example
Input
2
5
2 2 4 5 5
1 1 2 4 4
4 5 5 5 5
1 1 2 3 4
5
2 4 5 5 5
1 1 2 4 5
3 4 5 5 5
1 1 2 4 5
Output
3
1

E. Moon loves Mel Prime (Dark Blue)
time limit per test
2.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Donatello and Moon are working in their lab down in the sewers to synthesize a new chemical agent called Mel Prime! It is Moon's 2nd favorite.

The Mel starts with an initial power level of $$$1$$$ and then Moon performs the following operation on Mel exactly $$$K$$$ times: $$$$$$X = X + \gcd(X, Y)$$$$$$

Donatello trying to feed Moon.

Given the integers $$$Y$$$ and $$$K$$$, Calculate the final Mel Prime Power (MPP)!

Input

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

Each of the next $$$T$$$ lines contains two space-separated integers $$$Y$$$ and $$$K$$$ ($$$1 \le Y \le 10^9$$$, $$$1 \le K \le 10^9$$$).

Output

For each test case, print a single integer representing the final value of $$$X$$$ after $$$K$$$ operations are complete.

Example
Input
1
2 2
Output
4
Note
  • Initial State:
    • $$$X = 1$$$
  • Round 1:
    • Operation: $$$X = X + \gcd(X, Y)$$$
    • Calculation: $$$X = 1 + \gcd(1, 2) = 1 + 1$$$
    • Result: $$$X = 2$$$
  • Round 2:
    • Operation: $$$X = X + \gcd(X, Y)$$$
    • Calculation: $$$X = 2 + \gcd(2, 2) = 2 + 2$$$
    • Result: $$$X = 4$$$

F. Moon loves Mel (Purple)
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Donatello and Moon are working in their lab down in the sewers to synthesize a new chemical agent called Mel! It is Moon's favorite.

The Mel starts with an initial power level of $$$X$$$.

Donatello and Moon after realising the power of Mel.

In a single reaction step, Donatello's and Moon machine takes the smallest prime factor of the current power level and adds it to the total. This reaction process is repeated exactly $$$K$$$ times.

Note: If the power level is prime, its smallest prime factor is itself

Calculate the final Mel power level!

Input

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

For each test case, the only line of the test case with two space-separated numbers $$$X$$$ and $$$K$$$ ($$$2 \le X \le 10^9$$$ and $$$1 \le K \le 10^9$$$) — denotes the initial power level of Mel and the number of times the reaction process is repeated, respectively.

Output

For each test case print the final power level of Mel after exactly $$$K$$$ steps.

Example
Input
4
10 3
15 4
17 2
21 5
Output
16
24
36
32

G. Barakat loves Kylian Mbappé (Green)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

After seeing the newest ACM reel, Barakat was inspired so he went to sleep, and started dreaming about playing football with Kylian Mbappe, after the game,

Kylian Mbappé has brought two special boxes of pepperoni pizza down for some Ninja Turtles and Barakat. Each box contains exactly 5 slices, and every slice provides a specific amount of energy.

Barakat and Mbappé in his dream.

The ninja turtle and Barakt is hungry, but can only eat exactly 4 slices, and they must all be chosen from the same box. Calculate the maximum possible energy a turtle can gain!

Input

The first line is $$$5$$$ integers $$$a_1, b_1, c_1, d_1, e_1$$$ ($$$1 \le a_1, b_1, c_1, d_1, e_1 \le 100$$$) — denotes the energy values of the slices in the first box

The second line is $$$5$$$ integers $$$a_2, b_2, c_2, d_2, e_2$$$ ($$$1 \le a_2, b_2, c_2, d_2, e_2 \le 100$$$) — denotes the energy values of the slices in the second box.

Output

Print a single integer: the maximum possible total energy from eating 4 slices from a single box.

Example
Input
7 15 3 22 10
18 4 9 12 6
Output
54
Note

If they choose Box 1, the best 4 slices give: 7 + 15 + 22 + 10 = 54 energy.

If they choose Box 2, the best 4 slices give: 18 + 9 + 12 + 6 = 45 energy.

so the maximum possible total energy from eating 4 slices from a single box is 54

H. Shaaker loves Databases (Pink)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Shaaker recently has built a high-tech database containing the profiles of known mutants in New York City.

Each mutant's profile is uniquely defined by a sequence of $$$q$$$ yes/no traits (represented as 1s and 0s).

The Ninja Turtles have just encountered $$$n$$$ mysterious figures hiding in the sewers! Donatello uses his scanner to read the $$$q$$$ traits of each figure from Shaaker's database.

However, the Foot Clan is using signal jammers. Because of the interference, the data is corrupted: for every figure scanned, exactly one trait is guaranteed to be a lie (a 1 flipped to 0, or a 0 flipped to 1).

Given Shaaker's database and the corrupted scanner readings for the $$$n$$$ encounters, identify the correct original mutant from the database for each encounter!

It is guaranteed that each broken code can be uniquely connected to exactly one original secret code from the database.

Input

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

In each test case:

The first line contains three space-separated numbers, $$$d$$$ ($$$1 \le d \le 10^5$$$), $$$q$$$ ($$$1 \le q \le 20$$$), and $$$n$$$ ($$$1 \le n \le 10^5$$$) — denotes how many original secret codes, how many digits are in each code, and the number of broken codes, respectively.

Next $$$d$$$ lines: The original secret codes.

Next $$$n$$$ lines: The broken codes.

The sum of $$$d$$$ over all test cases does not exceed 100,000.

The sum of $$$n$$$ over all test cases does not exceed 100,000.

Output

For each test case, output $$$n$$$ lines. Each line should contain a single integer representing the 1-based index (the line number from $$$1$$$ to $$$d$$$) of the database entry that matches the corrected scan.

Example
Input
2
4 5 3
00000
10101
01110
11000
00100
10111
01010
5 6 4
000000
111000
100111
010101
001011
111100
100011
010001
001001
Output
1
2
3
2
3
4
5

I. Mocha loves FFT (Black)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Raph and Mocha have traded naps for competitive programming prep! Since they're tackling the ACPC (Arab Collegiate Programming Contest), they've been spending their afternoon grinding through complex algorithms. They were just in the middle of a deep dive into FFT (Fast Fourier Transform), trying to master polynomial multiplication, when a mysterious digital puzzle appeared on Raph's shell-phone—a parting gift from a defeated Kraang droid.

Mocha and Raphael.

You are given an array $$$a$$$ consisting of $$$n$$$ non-negative integers. In one round, every element in the array is updated simultaneously. Specifically, for each index $$$i$$$ ($$$1 \le i \le n$$$), the new value $$$a'_i$$$ is calculated as the bitwise XOR ($$$\oplus$$$) of the prefix minimum up to $$$i$$$ and the suffix maximum starting from $$$i$$$:

$$$$$$a'_i = \min(a_1, a_2, \dots, a_i) \oplus \max(a_i, a_{i+1}, \dots, a_n)$$$$$$

You will repeatedly apply this operation to the array. Your task is to determine the exact number of rounds required until all elements in the array become equal.

Since the number of rounds can potentially be very large, output the answer modulo $$$10^9 + 7$$$.

If the array will never reach a state where all elements are equal, output $$$-1$$$.

Input

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

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

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — denotes the elements of the array.

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

Output

For each test case, output a single integer — the minimum number of rounds required modulo $$$10^9 + 7$$$. If the elements will never become equal, output $$$-1$$$.

Example
Input
2
3
1 1 1
4
0 7 2 7
Output
0
1
Note

In the first test case, the array is initially $$$[1, 1, 1]$$$. All elements are already equal, so the number of rounds required is $$$0$$$.

In the second test case, the array is initially $$$[0, 7, 2, 7]$$$. After the first round, the array updates simultaneously:

  • $$$a'_1 = \min(0) \oplus \max(0, 7, 2, 7) = 0 \oplus 7 = 7$$$
  • $$$a'_2 = \min(0, 7) \oplus \max(7, 2, 7) = 0 \oplus 7 = 7$$$
  • $$$a'_3 = \min(0, 7, 2) \oplus \max(2, 7) = 0 \oplus 7 = 7$$$
  • $$$a'_4 = \min(0, 7, 2, 7) \oplus \max(7) = 0 \oplus 7 = 7$$$

After $$$1$$$ round, the array becomes $$$[7, 7, 7, 7]$$$. All elements are equal, so the answer is $$$1$$$.

J. Shoree loves Mex (White)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Moon had the worst breakup ever, again. His ex was way smarter than him, which devastated him.

So, he needed advice from the one and only Apple since Apple is also now in Germany, again. Apple decided to help Moon, he gave Moon a permutation of length $$$n$$$ and told him to go to Master Splinter.

Moon said, "4 JAYYED."

Master Splinter is testing Moon with the Shoree Puzzle

Moon is given a number $$$N$$$. Consider an array of length $$$N$$$ containing the integers from $$$1$$$ to $$$N$$$ exactly once (this is called a permutation).

There are $$$N!$$$ (N-factorial) possible ways to arrange this array. For every possible arrangement, Moon counts the number of inversions. An inversion is a pair of numbers where a larger number is placed before a smaller number.

Let $$$S$$$ be the set of all possible inversion counts you can get from every single arrangement. Your task is to find the $$$\operatorname{MEX}$$$ of the $$$S$$$.

Note: The $$$\operatorname{MEX}$$$ (Minimum EXcluded value) of an array is the smallest non-negative integer that is not in the array. For example:

  • The $$$\operatorname{MEX}$$$ of $$$[1, 2, 3]$$$ is $$$0$$$
  • The $$$\operatorname{MEX}$$$ of $$$[0, 1, 2]$$$ is $$$3$$$
  • The $$$\operatorname{MEX}$$$ of $$$[0, 1, 3]$$$ is $$$2$$$
Input

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

For each test case:

The first line and only line contains a single integer $$$n$$$ ($$$1 \le n \le 10^5$$$) — the size of the permutation.

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

Output

For each test case find the $$$\operatorname{MEX}$$$ of the $$$S$$$.

Example
Input
5
3
5
8
12
20
Output
4
11
29
67
191
Note

Explanation for the first sample case ($$$n=3$$$): For $$$n=3$$$, the possible permutations and their inversion counts are:

  • $$$[1, 2, 3] \to 0$$$ inversions
  • $$$[1, 3, 2] \to 1$$$ inversion
  • $$$[2, 1, 3] \to 1$$$ inversion
  • $$$[2, 3, 1] \to 2$$$ inversions
  • $$$[3, 1, 2] \to 2$$$ inversions
  • $$$[3, 2, 1] \to 3$$$ inversions
The set of inversion counts is $$$S = \{0, 1, 2, 3\}$$$. The smallest non-negative integer not in $$$S$$$ is $$$4$$$.

K. Tuffaha loves Light (Silver)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Leonardo is planning the nightly patrols to keep the city safe from the Foot Clan!

Tuffaha gave him a list of $$$n$$$ possible patrol zones. Each zone has a starting street number and an ending street number.

He needs to select exactly $$$k$$$ different patrol zones for his ninja squads. Then, from each chosen zone he must pick exactly one specific street number to set up a stealth ambush.

Leo mad at Tuffaha after Tuffaha chose the wrong streets to buy shawarma.

To make their team coordination absolutely perfect, Leonardo wants to maximize the bitwise AND of all $$$k$$$ chosen street numbers.

Calculate the highest possible bitwise AND he can achieve!

Input

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

The first line of each test case contains two integers $$$n$$$ ($$$1 \le n \le 10^5$$$) and $$$k$$$ ($$$1 \le k \le n$$$) — denotes the total number of patrol zones, and the number of zones Leonardo must choose respectively.

The second line of each test case contains two space-separated integers $$$l_i$$$ and $$$r_i$$$ ($$$0 \le l_i \le r_i \le 10^9$$$) — denotes the starting and ending street numbers of each zone.

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

Output

for each test case, print the maximum possible bitwise AND of the $$$k$$$ chosen street numbers.

Example
Input
3
3 1
5 10
2 4
15 20
2 2
3 7
5 10
3 2
1 2
4 5
8 9
Output
20
7
1

L. Blue server loves pets-pets-pets (Gold)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Splinter and his students

Splinter gave his students an array $$$a$$$ of $$$n$$$ integers. He would like the bitwise XOR of all elements to equal $$$0$$$.

To do so, the students may perform the following operation any number of times:

  • Choose an index $$$i$$$ ($$$1 \le i \le n$$$). Let $$$S$$$ be the XOR of all elements $$$a_j$$$ such that $$$a_j \neq a_i$$$. Replace $$$a_i$$$ with $$$S$$$. (If no such $$$j$$$ exists, replace $$$a_i$$$ with $$$0$$$.)

Find the minimum number of operations needed, and the number of distinct index sequences of that length that achieve it.

Two sequences are considered distinct if they differ in length or at any position.

Input

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

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

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — denotes the elements of the array.

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 minimum number of operations required, and the number of distinct sequences of that length that achieve the goal.

Example
Input
2
4
2 2 3 3
3
1 2 2
Output
0 1
1 1
Note

In the first test case, the array is initially $$$[2, 2, 3, 3]$$$. The XOR of all elements is $$$2 \oplus 2 \oplus 3 \oplus 3 = 0$$$. The minimum number of operations is $$$0$$$, and there is $$$1$$$ sequence of length $$$0$$$ (the empty sequence).

In the second test case, the array is initially $$$[1, 2, 2]$$$. The XOR of all elements is $$$1 \oplus 2 \oplus 2 = 1$$$. — If we choose $$$i=1$$$, $$$S$$$ is the XOR of elements not equal to $$$a_1=1$$$, which are $$$\{2, 2\}$$$. $$$S = 2 \oplus 2 = 0$$$. Replacing $$$a_1$$$ with $$$0$$$ gives $$$[0, 2, 2]$$$. The total XOR is $$$0 \oplus 2 \oplus 2 = 0$$$. This is one sequence of length $$$1$$$ starting with index $$$1$$$.

M. Jebreel loves Chelsea (Brown)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Leo stood in the damp shadows of the sewer lair, sliding a heavy briefcase toward Jebreel. Inside lay a crisp, royal blue Chelsea jersey and a stack of VIP passes to Stamford Bridge. Jebreel's hand shook as he took it; he was wearing his favorite Liverpool kit, and the thought of covering the Liver bird with Chelsea blue felt like a personal betrayal. To seal the deal, Jebreel pulled the blue shirt on, the Chelsea crest resting directly over his heart.

Jebreel With Chelsea jersey

You are given an array $$$a$$$ of $$$n$$$ integers. In one operation, you can choose an index $$$i$$$ ($$$1 \le i \le n$$$) and replace $$$a_i$$$ with the number of times its current value appears in the suffix $$$a_i, a_{i+1}, \dots, a_n$$$.

Find the minimum number of operations required to make all elements in the array equal. If it is impossible to make all elements equal, output $$$-1$$$.

Input

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

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

The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$0 \le a_i \le 10^9$$$) — denotes the elements of the array.

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

Output

For each test case, output a single integer — the minimum number of operations required to make all elements equal. If it is impossible, output $$$-1$$$.

Example
Input
2
3
7 7 7
2
1 2
Output
0
1
Note

In the first test case, the array is initially $$$[7, 7, 7]$$$. All elements are already equal, so the number of operations required is $$$0$$$.

In the second test case, the array is initially $$$[1, 2]$$$. If we choose index $$$i=2$$$, $$$a_2$$$ is replaced by the count of $$$2$$$ in the suffix $$$[2]$$$, which is $$$1$$$. The array becomes $$$[1, 1]$$$. The minimum number of operations is $$$1$$$.