/*
hdu5536 Trie树求异或最大
Author:lcy
Time:2017-10-18
给出n个数,求max{(si+sj)^sk},其中i,j,k不相等
把n个树的二进制加入Trie树(先加入高位,满足贪心性质),然后枚举si+sj,
在Trie树中尽量寻找每一位都与si+sj不同的值
注意,如果把si+sj加入Trie树,再去枚举sk,会超时。
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
using namespace std;
#define ull unsigned long long
#define ll long long
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
#define ms(a,b) memset(a,b,sizeof(a))
#define scfd(a) scanf("%d",a)
#define scflf(a) scanf("%lf",a)
#define scfs(a) scanf("%s",a)
#define ptfd(a) printf("%d\n",a)
#define ptfs(a) printf("%s\n",a)
#define showd(a,b) printf(a"=%d\n",b)
#define showlf(a,b) printf(a"=%lf\n",b)
#define shows(a,b) printf(a"=%s\n",b)
#define mmcp(a,b) memcpy(a,b,sizeof(b))
#define pb(a) push_back(a)
const int MAXN=1005;
set<int>st[MAXN];
struct node{
int ch[3];
int v,idx;
node(){
ms(ch,0);
}
};
int mxw;
struct trie{
vector<node>nd;
trie(){
nd.clear();
node t;
nd.push_back(t);
}
void init(){
nd.clear();
node t;
nd.push_back(t);
}
void push(ull x,int a){
//printf("x=%llu,a=%d\n",x,a);
ull s[40],ed=0;
ms(s,0);
while(x){
s[ed++]=x%2;
x>>=1;
}
int nnd=0;
frr(i,mxw-1,0){
if(!nd[nnd].ch[s[i]]){
node t;
t.v=s[i];
nd[nnd].ch[s[i]]=nd.size();
nd.push_back(t);
}
nnd=nd[nnd].ch[s[i]];
}
nd[nnd].idx=a;
}
}tr;
int now1,now2;
bool suc;
ull dfs(ull *s,ull *t,int x,int l,int lll){
//printf("x=%d,l=%d,lll=%d\n",x,l,lll);
if(l==-1){
if(now1!=tr.nd[x].idx&&now2!=tr.nd[x].idx)
suc=true;
ull ans=0;
ull tt=(1ull)<<(mxw-1);
if(suc){
fr(i,0,lll-1){
ans+=tt*t[i];
tt>>=1;
}
}
return ans;
}
if(tr.nd[x].ch[s[l]^1]){
t[lll]=s[l]^1;
ull xx=dfs(s,t,tr.nd[x].ch[s[l]^1],l-1,lll+1);
if(suc)return xx;
}
if(tr.nd[x].ch[s[l]]){
t[lll]=s[l];
return dfs(s,t,tr.nd[x].ch[s[l]],l-1,lll+1);
}
}
int cases,n;
ull k[MAXN];
int main(){
scfd(&cases);
while(cases--){
tr.init();
scfd(&n);
ull mx=0,mxx=0;
int mxidx;
fr(i,1,n){scanf("%llu",&k[i]);if(mx<k[i]){mx=k[i];mxidx=i;}}
fr(i,1,n)if(mxidx!=i&&k[i]>mxx)mxx=k[i];
mxw=0;
mx+=mxx;
while(mx){
mxw++;
mx>>=1;
}
fr(i,1,n)
tr.push(k[i],i);
ull ans=0;
fr(i,1,n)
fr(j,1,n)
if(i!=j){
ull s[40],tk[40];
ms(s,0);ms(tk,0);
ull t=k[i]+k[j];int ed=0;
while(t){
s[ed++]=t%2ull;
t>>=1;
}
now1=i,now2=j;
suc=false;
ull tt=dfs(s,tk,0,mxw-1,0);
ans=max(ans,tt^(k[i]+k[j]));
}
printf("%llu\n",ans);
}
return 0;
}