#define F first
#define S second
#define rep(i,a,b) for(int i=a;!(a==b&&i!=b)&&((i<=b&&b>=a)||(i>=b&&a>=b));i+=(a<=b?1:-1))
#define pb push_back
#define Fbitl __builtin_ffs
#define bit1 __builtin_popcount
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<string, string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
bool visa[(int)1e6] ;
ll cm[(int)1e6];
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
vi x(n+1);
ll sum = 0 ;
for ( int i = 1 ; i <= n ;i++) {
cin >> x[i];
sum += x[i] ;
cm[i] = sum ;
//cout << sum << " " ;
}
//cout << endl;
ll mx = 0 ;
for ( int i = 0 ; i <= n ; i++ ) {
//cout << i << " " << (i^k) << endl;
if (i+(i^k)<=n) {
if( mx < (ll)(cm[i]+(cm[n]-cm[n-((i)^(k))]))){
//cout << i << " " << (i^k) << " " << (ll)(cm[i]+(cm[n]-cm[n-((i)^(k))])) << endl;
mx = (ll)(cm[i]+(cm[n]-cm[n-((i)^(k))]));
}
}
}
cout << mx << endl;
}
return 0;
}
Copy