Universal Cup Judging System

Universal Cup

时间限制: 1 s 内存限制: 1024 MB 总分: 100 难度: [显示] 可 Hack ✓
统计

Given a non-negative integer sequence $A=a_1,a_2,\ldots,a_n$ of length $n$, define

$$F(A)=\max_{1\le k<n}((a_1\mathbin{\&}a_2\mathbin{\&}\cdots\mathbin{\&}a_k)+(a_{k+1}\mathbin{\&}a_{k+2}\mathbin{\&}\cdots\mathbin{\&}a_n)).$$

where $\&$ is the bitwise-and operator.

You can perform the swapping operation at most once: choose two indices $i$ and $j$ such that $1\le i<j\le n$ and then swap the values of $a_i$ and $a_j$.

Calculate the maximum possible value of $F(A)$ after performing at most one swapping operation.

Input

There are multiple test cases. The first line of the input contains an integer $T$ indicating the number of test cases. For each test case:

The first line contains an integer $n$ ($2\le n\le 10^5$) indicating the length of sequence $A$.

The second line contains $n$ integers $a_1,a_2,\cdots,a_n$ ($0\le a_i\le 10^9$) indicating the given sequence $A$.

It’s guaranteed that the sum of $n$ of all test cases will not exceed $10^5$.

Output

For each test case output one line containing one integer indicating the maximum possible value of $F(A)$ after performing at most one swapping operation.

Examples

Input 1

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

Output 1

7
3
3

Note

For the first sample test case, we can swap $a_4$ and $a_6$ so the sequence becomes $\{6,5,4,6,5,3\}$. We can then choose $k=5$ so that $F(A)=(6\mathbin{\&}5\mathbin{\&}4\mathbin{\&}6\mathbin{\&}5)+(3)=7$.

For the second sample test case, we can swap $a_2$ and $a_4$ so the sequence becomes $\{1,1,1,2,2,2\}$. We can then choose $k=3$ so that $F(A)=(1\mathbin{\&}1\mathbin{\&}1)+(2\mathbin{\&}2\mathbin{\&}2)=3$.

For the third sample test case we do not perform the swapping operation. We can then choose $k=2$ so that $F(A)=(1\mathbin{\&}1)+(2\mathbin{\&}2\mathbin{\&}2)=3$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.