#include<iostream>
#include<algorithm>
#include<deque>
#include<cmath>
#include<vector>
#include<string>
#include<bitset>
#define OmarNasr {ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
using namespace std;
long long p[200002], s[200002];
int main()
{
long long t, n, k;
cin >> t;
while (t--)
{
long long mx = 0;
cin >> n >> k;
for (int i = 1; i <= n; i++)
{
cin >> p[i];
p[i] += p[i - 1];
}
int c = 1, x = 0, y = 0;
s[n] = p[n];
for (int i = n - 1; i >= 1; i--)
s[c++] = p[n] - p[i];
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
if (1ll*i + j <= n)
{
if ((p[i] + s[j]) > mx && (i ^ j) == k) {
x = i, y = j;
break;
}
}
else break;
}
if (x > 0 || y > 0) {
mx = max((p[x] + s[y]), (p[y] + s[x]));
}
}
cout << mx << "\n";
}
}
Copy