#P9876. M. Minimal and Maximal XOR Sum

M. Minimal and Maximal XOR Sum

M. Minimal and Maximal XOR Sum

Problem Description

Given a permutation p1,p2,,pnp_1, p_2, \dots, p_n of 1n1 \sim n. You can perform several operations. In each operation you can choose an interval [l,r][l,r] and reverse the elements pl,pl+1,,prp_l,p_{l + 1}, \dots,p_r to pr,pr1,,plp_r, p_{r - 1}, \dots,p_l, the weight of this operation is rl+1r-l+1. You can perform any number of operations, and your goal is to make pi=ip_i=i at last. Please calculate the minimal and maximal XOR sum of the weight of all the operations.

Input

The input consists of multiple test cases. The first line contains a single integer TT (1T2×1051 \le T \le 2 \times 10 ^ 5) - the number of test cases. Description of the test cases follows. The first line of each test case contains one integer nn (1n1051\leq n\leq 10^5). The second line contains nn integers p1,p2,,pnp_1, p_2, \dots, p_n. It's guaranteed that n6×105\sum n \leq 6\times10^5.

Output

For each test case, print two integers - the minimal and maximal XOR sum of the weight of all the operations.

Sample Input

3
3
1 3 2
3
3 1 2
6
1 2 5 6 3 4

Sample Output

2 3
0 1
0 5

Source

2023“钉耙编程”中国大学生算法设计超级联赛(7)