#P1682B. AND Sorting
AND Sorting
Description
You are given a permutation of integers from to (each of them occurs exactly once). Initially, the permutation is not sorted (that is, for at least one ).
The permutation is called -sortable for some non-negative integer if it is possible to sort the permutation by performing the operation below some finite number of times:
- Choose two indices and such that .
- Swap and .
Here denotes the bitwise AND operation.
Find the maximum value of such that is -sortable. It can be shown that there always exists some value of such that is -sortable.
题面翻译
有 次询问。每次询问给你一个 的排列 ,保证此排列初始时没有排好序。你可以初始指定一个数 ,然后你每次可以交换两个数 ,此时必须满足 ,问要使得原排列有序的 的最大值。
Input
The input consists of multiple test cases. The first line contains a single integer — the number of test cases. Description of test cases follows.
The first line of each test case contains a single integer — the length of the permutation.
The second line of each test case contains integers (, all are distinct) — the elements of . It is guaranteed that is not sorted.
It is guaranteed that the sum of over all cases does not exceed .
Output
For each test case output a single integer — the maximum value of such that is -sortable.
Note
In the first test case, the only for which the permutation is -sortable are and , maximum of which is .
Sorting using :
- Swap and , .
- Swap and , .
- Swap and , .
Sorting using :
- Swap and , .
In the second test case, we must swap and which is possible only with .
相关
在下列比赛中: