//Optimise
#include <bits/stdc++.h>
using namespace std;

#define multitest 1
#ifdef Debug
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
	std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
#else
#define db(...)
#endif

using ll = long long;
#define f first
#define s second
#define pb push_back
const long long mod = 1000000007;
auto TimeStart = chrono::steady_clock::now();

const int nax = 25;
int n, k;
vector<int> a(nax);
int dp[21][21][40000]; // 40000 is chosen for safety it is the max value xor of k elements can assume that I assumed

int solve(int pos, int prevXor, int rem)
{
	if (pos == n) // Exhausted the element choice
	{
		if (rem == 0) // You have chosen k elements somehow, so this is valid
			return prevXor;
		else
			return 0; // Something went wrong returning the least value possible
	}
	if (rem == 0) // Whoa! You have to finish the taking process
		return prevXor;
	int &ret = dp[pos][rem][prevXor];
	if (ret >= 0) // Already solved
		return ret;
	ret = 0;
	// Now me have a choice
	ret = max(solve(pos + 1, prevXor, rem), solve(pos + 1, prevXor ^ a[pos], rem - 1));
	// Take the element or not -- Choose the best
	return ret;
}

void solve()
{
	cin >> n >> k;
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	cout << solve(0, 0, k) << '\n';
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
	while (t--)
		solve();
#ifdef TIME
	cerr << "\n\nTime elapsed: " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " seconds.\n";
#endif
	return 0;
}