P17091 『lnOI-R1』341799

Background

**Please pay attention to the special time limit of this problem.** **Please note the impact of constant factors on the running efficiency of your program.** --- This story is purely fictional. Any resemblance to actual events or persons is purely coincidental. > Susu never added Jiayu on QQ in the first place. During math class, Beike, sitting in front of her, suddenly turned around with a sly look: "Susu, Jiayu changed his QQ nickname." > > "Changed it to what?" > > "I love Susu." > > Susu's face sank: "Nonsense." > > As soon as the words left her mouth, the math teacher whipped around—but the next moment, he smiled instead: "Jiayu, if you want to find a partner, at least learn from a quadratic function—it has an axis of symmetry, halves on both sides. This 'I love Susu' of yours has no symmetry at all; it's purely a monomial—a one-sided crush. If you really want to confess, only a cardioid is romantic enough." > > Susu didn't know whether to laugh or cry: "Teacher, are you teaching math or matchmaking?" > > The teacher pushed up his glasses: "Saving the country by a roundabout route, understand? You won't take a straight ball anyway. Besides, this is called 'within math there naturally lies a fair lady.'" > > ![](https://cdn.luogu.com.cn/upload/image_hosting/s2l81omk.png)

Description

Sirus has a sequence $a$ of length $n$ consisting of non-negative integers. They need to divide these $n$ integers into two multisets $S_1$ and $S_2$. Note that $S_1$ and $S_2$ may be empty sets. Then, they will throw these two sets $S_1,S_2$ to Dylan. Knowing the division plan, Dylan will operate according to the following procedure: - Prepare an initially empty sequence $r$. - Let the initial sizes of the two sets be $s_1,s_2$ respectively. Then perform the following operations for a total of $\max(s_1,s_2)$ rounds: - If $S_1$ is non-empty, arbitrarily choose an element of $S_1$ as $x$ and delete it; otherwise take $x=0$. - If $S_2$ is non-empty, arbitrarily choose an element of $S_2$ as $y$ and delete it; otherwise take $y=0$. - Append $x\oplus y$ to the end of the sequence $r$. Here, $\oplus$ denotes the bitwise XOR operation. Now, Sirus and Dylan will play two games according to the above rules: - For the first game, both Sirus and Dylan hope to minimize the lexicographic order of $r$. - For the second game, Sirus hopes to maximize the lexicographic order of $r$, while Dylan hopes to minimize it. Where: for two sequences $a,b$, we say the lexicographic order of $a$ is smaller than that of $b$ if and only if there exists the smallest positive integer $p$ satisfying $a_p\ne b_p$, and $a_p

Input Format

**This problem has multiple test cases.** The first line contains a positive integer $T$, indicating the number of test cases. For each test case: The first line contains a positive integer $n$. The second line contains $n$ non-negative integers $a_i$.

Output Format

For each test case, output one line containing two non-negative integers, representing respectively the values of $$ \left(\sum_{i=1}^{|r|} (r_i+1)\times i\right) \pmod {10^9+7} $$ after the first game and after the second game. The two integers are separated by a single space.

Explanation/Hint

### Explanation of Sample $1$ Consider the first test case in Sample $1$, $a=[2,3,16,18]$. In the first game, Sirus will choose the division $S_1=\{2,16\},S_2=\{3,18\}$. Dylan will perform the following operations in order: - Choose $x=2\in S_1,y=3\in S_2$, at which point $x\oplus y=1$. After the operation, $r=[1],S_1=\{16\},S_2=\{18\}$. - Choose $x=16\in S_1,y=18\in S_2$, at which point $x\oplus y=2$. After the operation, $r=[1,2],S_1=S_2=\emptyset$. In the second game, Sirus will choose the division $S_1=\{2,3\},S_2=\{16,18\}$. Dylan will perform the following operations in order: - Choose $x=2\in S_1,y=18\in S_2$, at which point $x\oplus y=16$. After the operation, $r=[16],S_1=\{3\},S_2=\{16\}$. - Choose $x=3\in S_1,y=16\in S_2$, at which point $x\oplus y=19$. After the operation, $r=[16,19],S_1=S_2=\emptyset$. For the second test case, after the first game, $r=[0,1,18,30]$; after the second game, $r=[16,28,1]$. For the third test case, after the first game, $r=[0,0,0,0,2,5,8]$; after the second game, $r=[8,10,10,2,4,4,5]$. For the fourth test case, after the first game, $r=[0,0,0,0,0,3,5,7]$; after the second game, $r=[8,8,9,10,4,4,5,7]$. ### Constraints **This problem uses bundled testing.** For $100\%$ of the data, it is guaranteed that: - $1\le T,n\le 10^6$. - $\sum n\le 10^6$. - $0\le a_i\le 2^{30}-1$. ::cute-table{tuack} | Subtask number | Score | $\sum n \le$ | $a_i \le$ | Special property | Time limit | | :----------: | :----: | :------------: | :----------: | :----------: | :-:| | $1$ | $10$ | $10$ | $100$ | None | $1000\text{ ms}$ | $2$ | $5$ | $2\times 10^3$ | $2^{30}-1$ | $\text{A}$ | $2000\text{ ms}$ | $3$ | $15$ | ^ | ^ | $\text{BC}$ |^| | $4$ | $35$ | ^ | ^ | $\text{C}$ |^ | | $5$ | $20$ | ^ | ^ | None |^| | $6$ | $15$ | $10^6$ | ^ | ^ |$5000\text{ ms}$| Special property $\text{A}$: it is guaranteed that all $a_i$ are equal. Special property $\text{B}$: it is guaranteed that $\min \{a_i\}\ge 2^{29}$. Special property $\text{C}$: it is guaranteed that $\min \{a_i\}\ge 1$. **In particular**, for each subtask: - If you can correctly find the result of both games for all test data in it, you can obtain $100\%$ of the subtask's score. - If you can correctly find the result of the first game for all test data in it, but cannot correctly find the result of the second game for all test data in it, you can obtain $60\%$ of the subtask's score. - If you can correctly find the result of the second game for all test data in it, but cannot correctly find the result of the first game for all test data in it, you can obtain $45\%$ of the subtask's score. - Otherwise, you can obtain $0\%$ of the subtask's score. Finally, your total score is the sum of the scores of each subtask, rounded down, and the running time of your program is the maximum running time across all test points. **Note** that for each test case, even if you only intend to answer one of the games, you still need to output two integers on a line according to the format. Translated by QwenWork