#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(x) x.begin(),x.end()
#define ll long long
#define pb push_back
#define cin(x) for(auto &i:x)cin>>i;
#define cout(x) for(auto i:x)cout<<i<<" ";
#define copy(x,y) for(int i = 0 ; i < (int)x.size();i++)x[i]=y[i];
#define imn INT_MIN
#define imx INT_MAX
#define llmn LONG_LONG_MIN
#define llmx LONG_LONG_MAX
using namespace std;
const ll MOD = 1000000007;
const double PI = 3.14159265358979323846;
void solve()
{
int n,k;
cin>>n>>k;
vector<int> v(n);
cin(v);
int l=0 , r = n-1;
int cntl = 0,cntr = 0;
ll sum = 0;
while((cntl ^ cntr) != k and l<r)
{
if(v[l]>v[r])
{
sum+=v[l++];
cntl++;
}
else
{
sum+=v[r--];
cntr++;
}
}
cout<<sum<<endl;
}
int main()
{
FAST;
//freopen("Round1.in","r",stdin);
//freopen("overcode.in","w",stdout);
int t = 1;
cin >> t;
while (t--)
solve();
}
Copy