#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int ll;
ll mod=1e9+7;
ll a[200010];
ll b[200010];
ll tc,i,j,k,n,m,x;
string s,s1,s2;
vector< pair<ll,ll> > v;
int main(){
IOS
cin>>tc;
while(tc--){
v.clear();
cin>>n>>k;
for(i=0;i<=n;i++){
ll y=i^k;
if( (i+y)<=n )
v.push_back(make_pair(i,y));
}
for(i=0;i<n;i++){
cin>>a[i];
b[i]=a[i];
}
for(i=0;i<n/2;i++)
swap(b[i],b[n-i-1]);
for(i=1;i<n;i++)
a[i]+=a[i-1];
for(i=1;i<n;i++)
b[i]+=b[i-1];
ll ans=0;
for(auto x:v){
ll ff=x.first;
ll ss=x.second;
ll p=0,s=0;
if(ff)
p=a[ff-1];
if(ss)
s=b[ss-1];
ans=max(ans,p+s);
}
cout<<ans<<endl;
}
}
Copy