MITIT Winter 2025-26 Advanced Team Round
A. 67
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

The MITIT Winter 2025-26 contest takes place on December 6-7, 2025.

This is an interactive problem.

Busy Beaver has a secret array $$$a_1, \dots, a_N$$$, where $$$1 \leq a_i \leq 10^9$$$ for all $$$i$$$ and every two elements are coprime. (Two integers are coprime if the only positive integer dividing both is $$$1$$$.)

You may ask up to $$$100$$$ queries of the following form:

  • Pick two distinct indices $$$i$$$ and $$$j$$$. In response, you will receive the product $$$a_i \times a_j$$$.

Let $$$Q$$$ be the maximum number of queries you use to determine Busy Beaver's array. For full points, you must have $$$Q \leq \mathbf{67}$$$.

Input

Each test contains multiple test cases. The first line contains an integer $$$T$$$ ($$$1 \leq T \leq 1000$$$) — the number of test cases.

The first line of each test case contains an integer $$$N$$$ ($$$5 \leq N \leq 100$$$). After reading this line, you should begin the interaction.

Interaction

For each test case, begin by reading $$$N$$$.

To make a query, output "$$$\texttt{?}\;i\;j$$$" ($$$1 \leq i, j \leq n$$$; $$$i \neq j$$$) without quotes. Afterwards, you should read in a single integer — the product $$$a_i \times a_j$$$. You can make at most $$$100$$$ such queries in a single test case.

If you receive the integer $$$-1$$$ instead of an answer, it means your program has made an invalid query, has exceeded the limit of $$$100$$$ queries, or has given an incorrect answer on some previous test case. Your program must terminate immediately to receive a Wrong Answer verdict. Otherwise, you can get an arbitrary verdict because your solution will continue to read from a closed stream.

When you are ready to give the final answer, output "$$$\texttt{!}\;a_1\;\dots\;a_N$$$" ($$$1 \leq a_i \leq 10^9$$$) without quotes — Busy Beaver's array. Giving this answer does not count towards the limit of $$$100$$$ queries. Afterwards, your program must continue to solve the remaining test cases, or exit if all test cases have been solved.

After printing a query do not forget to output end of line and flush the output. To do this, use:

  • fflush(stdout) or cout.flush() in C++;
  • System.out.flush() in Java;
  • stdout.flush() in Python;
  • see your language's documentation for other languages.
Scoring
  • For full points, you must have $$$Q \leq \mathbf{67}$$$.
  • For partial points, using $$$67 \lt Q \leq 100$$$ queries will award $$$\lfloor 1.067^{125-Q} \rfloor$$$ points.
Example
Input
2
5

77

30

85

5

69

Output

? 1 2

? 3 4

? 4 5

! 7 11 6 5 17

? 1 5

! 1 40 61 41 69

Note

During an actual run the solution does not know the hidden array; it is shown here only to justify the sample.

In the first test case, the judge prints 5, so $$$N=5$$$. Its hidden array is $$$[7,11,6,5,17]$$$.

  • The program asks ? 1 2 and receives 77 from $$$7\times 11$$$.
  • It asks ? 3 4 and receives 30 from $$$6\times 5$$$.
  • It asks ? 4 5 and receives 85 from $$$5\times 17$$$.
The program then correctly outputs ! 7 11 6 5 17.

In the second test case, the judge prints 5. Its hidden array is $$$[1,40,61,41,69]$$$.

The program asks ? 1 5 and receives 69 from $$$1\times 69$$$. It then outputs ! 1 40 61 41 69, which matches the judge's array.

This illustrates one valid interaction sequence; any correct determination of the array using allowed queries is acceptable.

B. Avoid Copyright Infringement
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Busy Beaver has $$$X$$$ cards with the letter $$$\texttt{M}$$$, $$$Y$$$ cards with the letter $$$\texttt{I}$$$, and $$$Z$$$ cards with the letter $$$\texttt{T}$$$.

He wants to arrange these $$$X+Y+Z$$$ cards into a row following some constraints:

  • Busy Beaver likes variety, so no two adjacent cards can be equal;
  • Busy Beaver wants to avoid getting sued, so no three consecutive cards in a row can read $$$\texttt{MIT}$$$ or $$$\texttt{TIM}$$$.

Determine if he can do this. If it is possible, output an example.

Input

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

The only line of each test case contains three integers $$$X$$$, $$$Y$$$, and $$$Z$$$ ($$$0 \leq X, Y, Z \leq 10^5$$$). There is at least one card in each test case ($$$X+Y+Z \gt 0$$$).

The combined sum of $$$X+Y+Z$$$ across all test cases does not exceed $$$3 \cdot 10^5$$$.

Output

For each test case, if Busy Beaver cannot arrange all $$$X+Y+Z$$$ cards, output NO.

Otherwise, output YES. Then, output one line — a string of length $$$X+Y+Z$$$ consisting of characters $$$\texttt{M}$$$, $$$\texttt{I}$$$, and $$$\texttt{T}$$$, satisfying the constraints in the statement.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses. You can also output the string in any case.

Example
Input
2
1 1 1
3 0 0
Output
YES
ITM
NO
Note

In the first test case, there are $$$4$$$ possible combinations that will work: $$$\texttt{ITM}$$$, $$$\texttt{IMT}$$$, $$$\texttt{MTI}$$$, $$$\texttt{TMI}$$$. $$$\texttt{ITM}$$$ is one of them. It does not have equal adjacent cards, and there is no $$$\texttt{MIT}$$$ or $$$\texttt{TIM}$$$.

In the second test case, there is only one possible construction: $$$\texttt{MMM}$$$, but it is not valid, as there are adjacent $$$\texttt{M}$$$s.

C. Busy Beaver's Faulty Machine
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Deep in Busy Beaver's robotics lab sits an experimental Busy Beaver machine. Given a positive integer $$$X$$$ written in base $$$B$$$, it attempts to produce two positive integers $$$Y$$$ and $$$Z$$$ such that $$$X + Y = Z$$$, and the base-$$$B$$$ representations of $$$Y$$$ and $$$Z$$$ contain exactly the same multiset of digits.

The machine never produces leading zeroes and never outputs numbers with $$$2 \cdot 10^5$$$ or more digits. It has recently stopped functioning, so your task is to determine whether such $$$Y$$$ and $$$Z$$$ exist, and to output them if they do. You are given the digits of $$$X$$$ in base $$$B$$$ without leading zeroes.

Input

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 100$$$), the number of test cases.

Each test case consists of two lines. The first line of each test case contains two integers $$$N$$$ and $$$B$$$ ($$$1 \le N \le 10^5$$$; $$$2 \le B \le 10^5$$$).

The second line of each test case contains $$$N$$$ integers $$$a_1, a_2, \ldots, a_N$$$ ($$$0 \le a_i \le B-1$$$; $$$a_1 \ne 0$$$), representing the digits of $$$X$$$ in base $$$B$$$: $$$$$$ X = a_1 B^{N-1} + a_2 B^{N-2} + \cdots + a_N. $$$$$$

The sum of $$$N$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.

Output

For each test case, if no valid solution exists, output a single line containing NO.

Otherwise, output YES on the first line. On the second line output an integer $$$M$$$ ($$$1 \le M \le 2 \cdot 10^5$$$), the number of digits in both $$$Y$$$ and $$$Z$$$.

On the next line output $$$M$$$ digits $$$p_1, p_2, \ldots, p_M$$$ ($$$0 \le p_i \le B-1$$$; $$$p_1 \ne 0$$$), representing $$$$$$ Y = p_1 B^{M-1} + p_2 B^{M-2} + \cdots + p_M. $$$$$$ On the following line output $$$M$$$ digits $$$q_1, q_2, \ldots, q_M$$$ ($$$0 \le q_i \le B-1$$$; $$$q_1 \ne 0$$$), representing $$$$$$ Z = q_1 B^{M-1} + q_2 B^{M-2} + \cdots + q_M. $$$$$$ The digit sequences $$$(p_1, \ldots, p_M)$$$ and $$$(q_1, \ldots, q_M)$$$ must use exactly the same multiset of digits, and the integers they represent must satisfy $$$X + Y = Z$$$. You may print YES and NO in any mixture of uppercase and lowercase letters.

Example
Input
3
2 10
3 6
4 5
1 4 3 4
5 12
4 8 8 3 1
Output
YES
2
1 5
5 1
YES
4
1 4 3 2
3 4 2 1
NO
Note

In the first test case, with $$$B = 10$$$ and $$$X = 36$$$, a valid solution is $$$Y = 15$$$ and $$$Z = 51$$$, since $$$51 = 36 + 15$$$ and both numbers use the digits $$$\{1,5\}$$$.

In the second test case, with $$$B = 5$$$ and $$$X$$$ given by digits $$$(1, 4, 3, 4)_5$$$, $$$$$$ X = 1 \cdot 5^3 + 4 \cdot 5^2 + 3 \cdot 5^1 + 4 = 244. $$$$$$ One valid pair is $$$$$$ Y = (1, 4, 3, 2)_5 = 242, \qquad Z = (3, 4, 2, 1)_5 = 486, $$$$$$ which share the digit multiset $$$\{1,2,3,4\}$$$ and satisfy $$$X + Y = Z$$$.

D. Exam Room
time limit per test
1.5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Busy Beaver is hosting an upcoming exam for his students in the MITIT exam room. Due to last-minute preparation and bad testing, the students will need to come up to him to complain about things like bad difficulty distributions, server issues, misleading statements, and awful flavortexts without disturbing other students, so he needs to ensure that the seats are well separated.

The room has $$$N$$$ seats at points $$$P_i = (x_i,y_i)$$$, with Busy Beaver's desk located at $$$O = (0,0)$$$. He wants to choose a nonempty subset of the seats satisfying the following condition:

  • Each seat in the subset is strictly closer to Busy Beaver's desk than any other seat in the subset. Formally, for all pairs $$$P_i,P_j$$$ ($$$i \neq j$$$) in the subset, $$$\text{dist}(P_i,P_j) \gt \text{dist}(O,P_i)$$$, where $$$\text{dist}$$$ denotes Euclidean distance.

How many nonempty subsets satisfy this criterion? Since the answer may be enormous, output it modulo $$$998\,244\,353$$$.

Input

The first line contains a single integer $$$N$$$ ($$$1 \le N \le 500$$$).

The $$$i$$$-th of the next $$$N$$$ lines contains two integers $$$x_i$$$ and $$$y_i$$$ ($$$-10^9 \le x_i,y_i \le 10^9$$$).

All $$$N$$$ points in the input are distinct and not equal to $$$(0,0)$$$.

Output

Output a single integer — the number of valid nonempty subsets modulo $$$998\,244\,353$$$.

Scoring

There are four subtasks for this problem.

  • ($$$10$$$ points): $$$N$$$ does not exceed $$$15$$$.
  • ($$$10$$$ points): $$$N$$$ does not exceed $$$24$$$.
  • ($$$10$$$ points): $$$N$$$ does not exceed $$$80$$$.
  • ($$$70$$$ points): No additional constraints.
Examples
Input
2
1 2
2 1
Output
2
Input
3
1 2
2 1
1 -3
Output
5
Note

In the first sample, the two desks are $$$\sqrt{2}$$$ apart and $$$\sqrt{5}$$$ away from the origin, so either one or the other can be used.

In the second sample, the third desk is $$$\sqrt{10}$$$ away from the origin and $$$\sqrt{17}$$$ away from the closest other desk, so the third desk can always be used. The valid subsets are: $$$$$$ \{\text{desk }1\}, \{\text{desk }2\}, \{\text{desk }3\}, \{\text{desk }1, \text{desk }3\}, \{\text{desk }2, \text{desk }3\}. $$$$$$

E. Mahjong Connect
time limit per test
2 seconds
memory limit per test
512 megabytes
input
standard input
output
standard output

Busy Beaver has finally rage-quit Minesweeper and picked up Mahjong Connect instead. He has $$$N$$$ mahjong tiles at distinct locations on the Cartesian plane. Each tile $$$i$$$ has integer coordinates $$$(x_i, y_i)$$$ and a type $$$t_i$$$ with $$$1 \le t_i \le M$$$.

Two distinct tiles $$$i$$$ and $$$j$$$ match if and only if all of the following hold:

  • They share the same type, i.e. $$$t_i=t_j$$$;
  • They are on the same row or column, i.e. $$$x_i=x_j$$$ or $$$y_i=y_j$$$;
  • They are not blocked by other types, i.e. every tile strictly between them in that row or column (if any) has the same type. Formally:
    • If $$$y_i=y_j$$$, then for every tile $$$k$$$ with $$$y_k=y_i$$$ and $$$\min\{x_i,x_j\} \lt x_k \lt \max\{x_i,x_j\}$$$, we must have $$$t_k=t_i$$$;
    • If $$$x_i=x_j$$$, then for every tile $$$k$$$ with $$$x_k=x_i$$$ and $$$\min\{y_i,y_j\} \lt y_k \lt \max\{y_i,y_j\}$$$, we must have $$$t_k=t_i$$$.

A perfect matching is a partition of the $$$N$$$ tiles into $$$N/2$$$ disjoint pairs such that every pair is a valid match under the rules above. Determine whether a perfect matching exists. If it does, output any one perfect matching; otherwise, report that no perfect matching exists.

Input

The first line contains two integers $$$N$$$ and $$$M$$$ ($$$2\le N\le 3\cdot 10^5$$$, $$$1\le M\le 3\cdot 10^5$$$, $$$N$$$ is even).

The next $$$N$$$ lines describe the tiles. The $$$i$$$-th of these lines contains three integers $$$x_i$$$, $$$y_i$$$ and $$$t_i$$$ ($$$|x_i|,|y_i|\le 10^9$$$, $$$1\le t_i\le M$$$).

It is guaranteed that the pairs $$$(x_i,y_i)$$$ are distinct.

Output

If no perfect matching exists, print a single line containing NO.

Otherwise, print a single line containing YES. Then print $$$N/2$$$ lines, each containing two integers $$$i$$$ and $$$j$$$ ($$$1\le i,j\le N$$$, $$$i\neq j$$$), indicating that tiles $$$i$$$ and $$$j$$$ form a matched pair.

Each index from $$$1$$$ to $$$N$$$ must appear in exactly one pair. The pairs may be printed in any order, and within each pair, the order of $$$i$$$ and $$$j$$$ does not matter.

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

Examples
Input
4 2
-1 0 1
1 0 1
0 -1 2
0 1 2
Output
YES
1 2
3 4
Input
4 2
-1 0 1
1 0 1
0 0 2
0 1 2
Output
NO
Input
22 3
1 1 2
1 2 2
1 3 2
1 4 1
2 3 2
3 2 1
3 1 2
4 3 2
5 4 1
5 3 1
5 2 1
5 1 1
7 1 3
7 2 3
7 3 3
7 4 3
9 4 3
10 4 3
11 4 3
10 3 1
10 2 1
10 1 3
Output
YES
1 7
2 3
4 9
5 8
6 11
10 12
13 22
14 15
16 17
18 19
20 21
Note

In the first test case, we can pair up the tiles at $$$(-1,0),(1,0)$$$ and $$$(0,-1),(0,1)$$$, respectively.

In the second test case, we cannot do the same thing because the tile at $$$(0,0)$$$ blocks the connection between $$$(-1,0)$$$ and $$$(1,0)$$$.

The visualization of the third test case is as follows (different colors represent different types of tiles):

Note again that, if the answer is YES, any valid pairing with any order will be accepted. For instance, for the first sample, the following output is also acceptable:

YES
4 3
1 2

F. Collatz Conjecture
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Busy Beaver recently learned about the Collatz Conjecture! He has written down a sequence of $$$N$$$ positive integers $$$a_1, a_2, \ldots , a_N$$$ on a blackboard to experiment with and further his understanding of the conjecture. He also notices a counter left on a table and comes up with the following game to play.

The counter initially starts at the number $$$1$$$. A move consists of picking a number on the blackboard and replacing it:

  • If the counter shows an odd number, Busy Beaver must pick some odd number $$$x$$$ on the board and replace it with $$$3x+1$$$.
  • If the counter shows an even number, he must pick some even number $$$y$$$ on the board and replace it with $$$\frac{y}{2}$$$.
After each replacement, Busy Beaver increments the counter by $$$1$$$. If he cannot make any move, the game ends, and his score is the number of moves he performed (equivalently, one less than the number on the counter).

Busy Beaver wants to play this game for as long as possible. Help him determine the maximum number of moves he can perform before he runs out of moves!

Input

The first line contains the number of test cases $$$T$$$ ($$$1 \le T \le 500$$$).

The first line of each test case contains a single integer $$$N$$$ ($$$1 \le N \le 500$$$), the number of positive integers on the blackboard.

The second line of each test case contains $$$N$$$ positive integers $$$a_1, a_2, \ldots , a_N$$$ ($$$1 \le a_i \le 10^6$$$). It can be shown that any Collatz sequence started on a number at most $$$10^6$$$ will reach $$$1$$$ after at most $$$524$$$ moves. Additionally, it can also be shown that Busy Beaver will eventually run out of moves and that he never writes a number larger than $$$10^{18}$$$ on the blackboard.

The sum of $$$N$$$ across all test cases does not exceed $$$500$$$.

Output

For each test case, output a single integer — the maximum number of moves that Busy Beaver can perform.

Example
Input
6
1
3
5
2 4 6 8 10
6
4 5 6 6 5 4
26
837799 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
9
3 1 4 1 5 9 2 6 5
10
123456 678910 111213 141516 171819 202122 232425 262728 293031 323334
Output
4
0
14
164
34
60
Note

In the first test case, Busy Beaver only has one number on the blackboard which is the number $$$3$$$.

  • On the first move, Busy Beaver replaces the odd number $$$3$$$ with $$$3(3) + 1 = 10$$$.
  • On the second move, Busy Beaver replaces the even number $$$10$$$ with $$$\frac{10}{2} = 5$$$.
  • On the third move, Busy Beaver replaces the odd number $$$5$$$ with $$$3(5) + 1 = 16$$$.
  • On the fourth move, Busy Beaver replaces the even number $$$16$$$ with $$$\frac{16}{2} = 8$$$.
At this point, Busy Beaver cannot make any moves, so the maximum number of moves is $$$4$$$.

In the second test case, Busy Beaver cannot make any move since there are no odd numbers on the blackboard.

G. Busy Beaver's Dam Logs
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Busy Beaver has arranged $$$N$$$ logs in a line to form the base of his dam. Each log has an integer quality value between $$$-2$$$ and $$$2$$$. From time to time, some logs are replaced. He occasionally wants to know if there is a contiguous segment of logs whose total quality equals a given nonzero number $$$X$$$, and may also want to know the segment. Help Busy Beaver process all updates and queries efficiently.

Input

The first line of input contains an integer $$$T$$$ ($$$1 \le T \le 10^4$$$) — the number of testcases.

The first line of each test case contains two integers $$$N$$$ and $$$Q$$$ ($$$1 \le N,Q \le 2\cdot 10^5$$$) — the size of the array and the number of queries, respectively.

The second line of each test case contains $$$N$$$ integers $$$a_1, a_2, \dots, a_N$$$ ($$$-2 \le a_i \le 2$$$) — the qualities of the logs.

The next $$$Q$$$ lines of each test case are of two forms:

  • $$$1\ i\ x$$$ ($$$1 \le i \le N$$$, $$$-2\le x\le 2$$$) — set the quality of the $$$i$$$-th log to $$$x$$$.
  • $$$2\ X$$$ ($$$-2N\le X \le 2N$$$, $$$X\ne 0$$$) — find a contiguous segment of logs with total quality $$$X$$$.

There is at least one query of the second type.

The sum of $$$N$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

The sum of $$$Q$$$ over all test cases does not exceed $$$2\cdot 10^5$$$.

Output

For each query of the second type, if a valid contiguous segment exists, print YES on the first line, followed by the left and right indices of that segment $$$l$$$ and $$$r$$$ on the next line ($$$1 \le l \le r \le N$$$). If no such segment exists, print NO on a single line.

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

Scoring

There are four subtasks in this problem. You can receive $$$50\%$$$ of the points for each subtask if the YES/NO answers are correct, but the indices are incorrect. To obtain these partial points, you must still output integers $$$l$$$ and $$$r$$$ between $$$1$$$ and $$$N$$$ after all YES answers.

  • ($$$10$$$ points): The sum of $$$N$$$ over all test cases is at most $$$10^3$$$, and the sum of $$$Q$$$ over all test cases is at most $$$10^3$$$.
  • ($$$20$$$ points): $$$-1\le a_i\le 1$$$ for all $$$i$$$, and for any query of the first type, $$$-1\le x\le 1$$$.
  • ($$$30$$$ points): $$$0\le a_i\le 2$$$ for all $$$i$$$, and for any query of the first type, $$$0\le x\le 2$$$.
  • ($$$40$$$ points): No additional constraints.
Example
Input
4
5 5
-1 2 0 -2 1
1 2 1
2 1
1 4 2
2 3
2 -2
4 3
-1 -1 -1 -1
1 4 1
2 -1
2 -4
6 6
1 -1 1 -1 1 -1
1 3 0
2 1
2 -2
2 3
1 3 2
2 1
6 3
0 0 0 0 0 0
2 2
1 1 1
2 1
Output
YES
2 2
YES
3 5
NO
YES
2 2
NO
YES
1 1
YES
2 4
NO
YES
1 1
NO
YES
1 1
Note

For the first test case:

  • The initial array is $$$[-1, 2, 0, -2, 1]$$$.
  • After the first query $$$1\ 2\ 1$$$, the array becomes $$$[-1, 1, 0, -2, 1]$$$.
  • The second query $$$2\ 1$$$ asks for a contiguous segment summing to $$$1$$$, which can be achieved by $$$[1]$$$ (element $$$2$$$).
  • After the third query $$$1\ 4\ 2$$$, the array becomes $$$[-1, 1, 0, 2, 1]$$$.
  • The fourth query $$$2\ 3$$$ asks for a contiguous segment summing to $$$3$$$, which can be achieved by $$$[1,0,2]$$$ (elements $$$2$$$–$$$4$$$).
  • The fifth query $$$2\ {-2}$$$ asks for a contiguous segment summing to $$$-2$$$. It can be checked that no such subarray exists.

For the second test case:

  • The initial array is $$$[-1, -1, -1, -1]$$$.
  • After the first query $$$1\ 4\ 1$$$, the array becomes $$$[-1, -1, -1, 1]$$$.
  • The second query $$$2\ {-1}$$$ asks for a contiguous segment summing to $$$-1$$$, which can be achieved by $$$[-1]$$$ (any of the first three elements).
  • The third query $$$2\ {-4}$$$ asks for a contiguous segment summing to $$$-4$$$. It can be checked that no such subarray exists.

H. Snacks Scheduling
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Busy Beaver has $$$N$$$ favorite snack spots along the Charles River, labeled $$$1, 2, \dots, N$$$. Each day, he wishes to enjoy a snack at spot $$$i$$$ during time $$$i$$$. What a perfectly optimized routine!

Unfortunately, the geese have other plans. For each index $$$i$$$, a goose occupies spot $$$a_i$$$ at time $$$i$$$. Busy Beaver absolutely refuses to visit the same spot as a goose, so his final schedule $$$p_1,p_2,\dots,p_N$$$ must be a permutation of $$$1,2,\dots,N$$$ that satisfies $$$p_i \neq a_i$$$ for every $$$1 \le i \le N$$$.

Busy Beaver also wants to keep his life predictable. Among all valid schedules $$$p$$$, determine the minimum possible number of inversions$$$^{\text{∗}}$$$ $$$p$$$ can have. If no valid schedule exists, output $$$-1$$$.

$$$^{\text{∗}}$$$Recall that the number of inversions in $$$p$$$ is defined as the number of pairs $$$(i,j)$$$ with $$$1 \le i \lt j \le N$$$ and $$$p_i \gt p_j$$$.

Input

The first line contains a single integer $$$T$$$ ($$$1 \le T \le 3 \cdot 10^5$$$) representing the number of test cases.

The first line of each test case contains a single integer $$$N$$$ ($$$1 \le N \le 3\cdot 10^5$$$).

The second line of each test case contains $$$N$$$ integers $$$a_1,a_2,\dots,a_N$$$ ($$$1 \le a_i \le N$$$).

The sum of $$$N$$$ over all test cases does not exceed $$$3 \cdot 10^5$$$.

Output

For each test case, print a single integer: the minimum possible inversion count among all permutations $$$p$$$ satisfying $$$p_i \ne a_i$$$ for all $$$i$$$. If no valid schedule exists, print $$$-1$$$.

Example
Input
4
3
2 3 1
4
1 2 3 4
5
1 1 1 1 1
10
1 1 1 1 1 10 10 10 10 10
Output
0
2
-1
9
Note

In the first test case, no position satisfies $$$a_i=i$$$, so Beaver can use his original routine $$$p=[1,2,3]$$$, which has $$$0$$$ inversions.

In the second test case, a valid schedule is $$$p=[2,1,4,3]$$$, which has exactly $$$2$$$ inversions.

In the third test case, spot $$$1$$$ is occupied throughout the day, so that poor Busy Beaver fails to schedule. What a pity!

I. RMQ
time limit per test
5 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

This is an interactive problem.

Busy Beaver has a secret array $$$a_1,a_2,\dots,a_N$$$ of distinct positive integers between $$$1$$$ and $$$10^9$$$. For $$$1 \le l \le r \le N$$$, Busy Beaver defines $$$f(l,r)$$$ to be equal to $$$\min(a_l,a_{l+1},\dots,a_r)$$$.

Busy Beaver allows you to ask some queries to uncover information about the array. In a query, you can specify $$$l$$$ and $$$r$$$ ($$$1 \le l \le r \le N$$$), and Busy Beaver will tell you the value of $$$f(l,r)$$$ for a cost of $$$\frac{1}{r-l+1}$$$. You must ensure that the total cost of all queries is at most $$$1$$$.

After making all your queries, you report to Busy Beaver a list of pairs $$$(l,r)$$$ for which you determined the value of $$$f(l,r)$$$. If any of your answers are wrong, Busy Beaver will be displeased and award you $$$0$$$ points. Otherwise, your score will depend on the fraction of the $$$\frac{N(N+1)}{2}$$$ pairs $$$(l,r)$$$ with $$$1 \le l \le r \le N$$$ where you determined a value for $$$f(l,r)$$$ (see the Scoring section for more details).

To reduce the size of the output, you report your knowledge using $$$k$$$ tuples of the form $$$(l_{min},l_{max},r_{min},r_{max},v)$$$, where $$$1 \le l_{min} \le l_{max} \le r_{min} \le r_{max} \le N$$$ and $$$1 \le v \le 10^9$$$. Each tuple declares that $$$f(l,r) = v$$$ for all $$$l_{min} \le l \le l_{max}$$$ and $$$r_{min} \le r \le r_{max}$$$. Any pairs $$$(l,r)$$$ that do not correspond to any tuple are treated as unspecified. It is allowed to have multiple tuples that describe the same pair $$$(l,r)$$$, but you will receive $$$0$$$ points if these tuples indicate inconsistent values.

Interaction

The first line of input contains a single integer $$$N$$$ ($$$1 \le N \le 10^5$$$), the length of Busy Beaver's secret array.

You may repeatedly ask queries by outputting a line of the form "? l r", where $$$1 \le l \le r \le N$$$. Then, the judge will respond with a single integer, denoting the value of $$$f(l,r)$$$. If you exceed a total cost of $$$1$$$, the judge will instead respond with $$$-1$$$, and you should terminate your program immediately to receive a Wrong Answer verdict.

After you are finished with your queries, first output a line of the form "! k" ($$$0 \le k \le 2N$$$), representing that you will describe your knowledge of $$$f$$$ using $$$k$$$ tuples $$$(l_{min},l_{max},r_{min},r_{max},v)$$$.

Then, the next $$$k$$$ lines should each contain $$$5$$$ space-separated integers $$$l_{min}$$$, $$$l_{max}$$$, $$$r_{min}$$$, $$$r_{max}$$$, and $$$v$$$, specifying a tuple.

The interactor is not adaptive, meaning that Busy Beaver will not change the entries of his secret array $$$a$$$ in response to your queries.

Scoring

For all test cases used for scoring, $$$N = 10^5$$$.

If you exceed a cost of $$$1$$$ or any of the values you claim for $$$f(l,r)$$$ are incorrect, you will receive $$$0$$$ points and a Wrong Answer verdict.

Otherwise, let $$$x$$$ be the fraction of the $$$\frac{N(N+1)}{2}$$$ values of $$$f(l,r)$$$ that you specified a value for. Your score for the test case will be equal to $$$$$$ \left\lfloor \min\left(100,100 \cdot \frac{x}{0.8}\right) \right\rfloor. $$$$$$ In particular, if $$$x \ge 0.8$$$, then you will receive full points for the test case.

Your final score will be the minimum score over all test cases.

Example
Input
6

31

26

53
Output

? 1 3

? 1 6

? 5 6

! 4
1 1 3 3 31
1 4 4 6 26
2 3 5 5 26
5 5 6 6 53
Note

Note that the sample does not satisfy $$$N = 10^5$$$, so it will not be included in the actual test cases. It is provided only to illustrate the interaction format.

In the sample, Busy Beaver's secret array is $$$a = [31,41,59,26,53,58]$$$. You decide to make the following queries:

  • $$$l = 1$$$, $$$r = 3$$$: Busy Beaver calculates $$$f(1,3) = \min(31,41,59) = 31$$$ and tells you the value $$$31$$$.
  • $$$l = 1$$$, $$$r = 6$$$: Busy Beaver calculates $$$f(1,6) = \min(31,41,59,26,53,58) = 26$$$ and tells you the value $$$26$$$.
  • $$$l = 5$$$, $$$r = 6$$$: Busy Beaver calculates $$$f(5,6) = \min(53,58) = 53$$$ and tells you the value $$$53$$$.

Note that the total cost of all your queries is $$$\frac13+\frac16+\frac12 = 1$$$, which does not exceed $$$1$$$ as required.

From this information, you report to Busy Beaver the following values of $$$f(l,r)$$$ you have deduced:

  • $$$f(l,r) = 31$$$ for all $$$1 \le l \le 1$$$, $$$3 \le r \le 3$$$.
  • $$$f(l,r) = 26$$$ for all $$$1 \le l \le 4$$$, $$$4 \le r \le 6$$$.
  • $$$f(l,r) = 26$$$ for all $$$2 \le l \le 3$$$, $$$5 \le r \le 5$$$. This overlaps with the information in the previous line, but is a valid output.
  • $$$f(l,r) = 53$$$ for all $$$5 \le l \le 5$$$, $$$6 \le r \le 6$$$.
After removing overlaps, you reported $$$14$$$ of the values of $$$f(l,r)$$$ out of the $$$\frac{N(N+1)}{2} = 21$$$ distinct pairs $$$(l,r)$$$. Therefore, Busy Beaver will calculate $$$x = \frac{14}{21}$$$ and give you a score of $$$$$$ \left\lfloor 100 \cdot \frac{14/21}{0.8} \right\rfloor = \left\lfloor 83.\bar{3} \right\rfloor = 83 $$$$$$ for this interaction.