#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
using std::vector;
struct node
    {
        char key;
        int value;
    };
int main()
{
	int v;
	std::cin>>v;
	for(int i=0; i<v ;i++)
	{
		int n,k;
		std::cin>>n>>k;
		vector<int> a ;
		a.resize(n*k);
		int count=0;
		for(int j=0; j< n*k;j++)
		{
			cin>>a[j];
		}
		for(int j=1; j< k+1;j++)
		{
				count+=a[n*k-j*(n/2+1)];
			}
		cout<<count<<"\n";

	}

	return 0;
//	int v;
//	std::cin>>v;
//	for(int i=0; i<v ;i++)
//	{
//		int n;
//		std::cin>>n;
//		unordered_map<char, int> hash;
//		int flag=0;
//		for(int j=0; j<n;j++){
//			string input;
//			cin>>input;
//			for(int k=0; k<input.length();k++)
//			{
//					if(hash.find(input[k])==hash.end())
//					{
//						hash[input[k]]=1;
//					}
//					else
//					{
//						hash[input[k]]++;
//					}
//			}
//		}
//		unordered_map<char, int>:: iterator p;
//		for(p =hash.begin(); p!=hash.end();p++)
//		{
////			cout<<hash[k].key<<" "<<hash[k].value<<"\n";
//			if(p->second%n!=0)
//			{
//				flag=1;
//				break;
//			}
//		}
//		if(flag==1)
//		cout<<"NO\n";
//		else
//		cout<<"YES\n";
//	}
//	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using std::vector;
int main()
{
	int v;
	std::cin>>v;
	for(int i=0; i<v ;i++)
	{
		int n,k;
		std::cin>>n>>k;
		vector<long long int> a ;
		a.resize(n*k);
		long long int count=0;
		for(int j=0; j< n*k;j++)
		{
			cin>>a[j];
		}
		for(int j=1; j< k+1;j++)
		{
			int m=(n/2+1);
			count+=a[n*k-j*m];
		}

		cout<<count<<"\n";
	}

	return 0;

}


#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
using std::vector;
struct node
    {
        char key;
        int value;
    };
int main()
{
	int v;
	std::cin>>v;
	for(int i=0; i<v ;i++)
	{
		int n,k;
		std::cin>>n>>k;
		vector<long> a ;
		a.resize(n*k);
		long count=0;
		for(int j=0; j< n*k;j++)
		{
			cin>>a[j];
		}
		for(int j=1; j< k+1;j++)
		{
				count+=a[n*k-j*(n/2+1)];
			}
		cout<<count<<"\n";

	}

	return 0;
//	int v;
//	std::cin>>v;
//	for(int i=0; i<v ;i++)
//	{
//		int n;
//		std::cin>>n;
//		unordered_map<char, int> hash;
//		int flag=0;
//		for(int j=0; j<n;j++){
//			string input;
//			cin>>input;
//			for(int k=0; k<input.length();k++)
//			{
//					if(hash.find(input[k])==hash.end())
//					{
//						hash[input[k]]=1;
//					}
//					else
//					{
//						hash[input[k]]++;
//					}
//			}
//		}
//		unordered_map<char, int>:: iterator p;
//		for(p =hash.begin(); p!=hash.end();p++)
//		{
////			cout<<hash[k].key<<" "<<hash[k].value<<"\n";
//			if(p->second%n!=0)
//			{
//				flag=1;
//				break;
//			}
//		}
//		if(flag==1)
//		cout<<"NO\n";
//		else
//		cout<<"YES\n";
//	}
//	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using std::vector;
int main()
{
	int v;
	std::cin>>v;
	for(int i=0; i<v ;i++)
	{
		int n,k;
		std::cin>>n>>k;
		vector<int> a ;
		a.resize(n*k);
		int count=0;
		for(int j=0; j< n*k;j++)
		{
			cin>>a[j];
		}
		for(int j=1; j< k+1;j++)
		{
			int m=(n/2+1);
				count+=a[n*k-j*m];
			}

		cout<<count<<"\n";
	}

	return 0;

}


#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

/*
int bs(int l,int r,int n)
{
    int mid,res=inf;

    while(l<=r)
    {
        mid=l+(r-l)/2;

        if(check(mid,n))
        {
            r=mid-1;
            res=min(res,mid);
        }
        else
            l=mid+1;

    }

    return res;
}
*/

//--------------------------code starts here---------------------------------------

/*LL a[1005][1005],mod=1e9+7;

void nPr()
{
    for(LL i=0; i<1005; i++)
    {
        a[i][0]=1;
    }

    for(LL i=1; i<1005; i++)
        for(LL j=1; j<1005; j++)
            a[i][j] =(i * a[i-1][j-1])%mod;
}*/
//--------------------Articulation point/node----------------------

vector<int> v;

int main()
{
    int t;
    si(t);

    while(t--)
    {
        v.clear();

        int n,k,x;
        sii(n,k);
        //v.pb(0);

        Rep(i,1,n*k)
        {
            si(x);
            v.pb(x);
        }

        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());

        int cnt=0,sum1=0,sum2=0,rnge=(n/2)+1;

        for(int i=0;i<v.size();i++)
        {
            cnt++;

            if(cnt==rnge)
            {
                sum1+=v[i];
                k--;
                cnt=0;
            }

            if(k==0)
                break;
        }

        printf("%d\n",sum1);
    }

    return 0;
}


#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

/*
int bs(int l,int r,int n)
{
    int mid,res=inf;

    while(l<=r)
    {
        mid=l+(r-l)/2;

        if(check(mid,n))
        {
            r=mid-1;
            res=min(res,mid);
        }
        else
            l=mid+1;

    }

    return res;
}
*/

//--------------------------code starts here---------------------------------------

/*LL a[1005][1005],mod=1e9+7;

void nPr()
{
    for(LL i=0; i<1005; i++)
    {
        a[i][0]=1;
    }

    for(LL i=1; i<1005; i++)
        for(LL j=1; j<1005; j++)
            a[i][j] =(i * a[i-1][j-1])%mod;
}*/
//--------------------Articulation point/node----------------------

vector<int> v;

int main()
{
    int t;
    si(t);

    while(t--)
    {
        v.clear();

        int n,k,x;
        sii(n,k);

        Rep(i,1,n*k)
        {
            si(x);
            v.pb(x);
        }

        int cnt=0,sum1=0,sum2=0,rnge=((n)/2)+1;

        for(int i=v.size()-1;i>=0;i--)
        {
            cnt++;

            if(cnt==rnge)
            {
                sum1+=v[i];
                k--;
                cnt=0;
            }

            if(k==0)
                break;
        }

        printf("%d\n",max(sum1,sum2));
    }

    return 0;
}


#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

/*
int bs(int l,int r,int n)
{
    int mid,res=inf;

    while(l<=r)
    {
        mid=l+(r-l)/2;

        if(check(mid,n))
        {
            r=mid-1;
            res=min(res,mid);
        }
        else
            l=mid+1;

    }

    return res;
}
*/

//--------------------------code starts here---------------------------------------

/*LL a[1005][1005],mod=1e9+7;

void nPr()
{
    for(LL i=0; i<1005; i++)
    {
        a[i][0]=1;
    }

    for(LL i=1; i<1005; i++)
        for(LL j=1; j<1005; j++)
            a[i][j] =(i * a[i-1][j-1])%mod;
}*/
//--------------------Articulation point/node----------------------

vector<LL> v;

int main()
{
    int t;
    si(t);

    while(t--)
    {
        v.clear();

        int n,k,x;
        sii(n,k);

        Rep(i,1,n*k)
        {
            si(x);
            v.pb(x);
        }

        LL cnt=0,sum1=0,sum2=0,rnge=(n/2)+1;

        for(int i=v.size()-1;i>=0;i--)
        {
            cnt++;

            if(cnt==rnge)
            {
                sum1+=v[i];
                k--;
                cnt=0;
            }

            if(k==0)
                break;
        }

        printf("%lld\n",max(sum1,sum2));
    }

    return 0;
}


#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

/*
int bs(int l,int r,int n)
{
    int mid,res=inf;

    while(l<=r)
    {
        mid=l+(r-l)/2;

        if(check(mid,n))
        {
            r=mid-1;
            res=min(res,mid);
        }
        else
            l=mid+1;

    }

    return res;
}
*/

//--------------------------code starts here---------------------------------------

/*LL a[1005][1005],mod=1e9+7;

void nPr()
{
    for(LL i=0; i<1005; i++)
    {
        a[i][0]=1;
    }

    for(LL i=1; i<1005; i++)
        for(LL j=1; j<1005; j++)
            a[i][j] =(i * a[i-1][j-1])%mod;
}*/
//--------------------Articulation point/node----------------------

vector<int> v;

int main()
{
    int t;
    si(t);

    while(t--)
    {
        v.clear();

        int n,k,x;
        sii(n,k);

        Rep(i,1,n*k)
        {
            si(x);
            v.pb(x);
        }

        int cnt=0,sum1=0,sum2=0,rnge=(n/2)+1;

        for(int i=v.size()-1;i>=0;i--)
        {
            cnt++;

            if(cnt==rnge)
            {
                sum1+=v[i];
                k--;
                cnt=0;
            }

            if(k==0)
                break;
        }

        printf("%d\n",max(sum1,sum2));
    }

    return 0;
}


#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

/*
int bs(int l,int r,int n)
{
    int mid,res=inf;

    while(l<=r)
    {
        mid=l+(r-l)/2;

        if(check(mid,n))
        {
            r=mid-1;
            res=min(res,mid);
        }
        else
            l=mid+1;

    }

    return res;
}
*/

//--------------------------code starts here---------------------------------------

/*LL a[1005][1005],mod=1e9+7;

void nPr()
{
    for(LL i=0; i<1005; i++)
    {
        a[i][0]=1;
    }

    for(LL i=1; i<1005; i++)
        for(LL j=1; j<1005; j++)
            a[i][j] =(i * a[i-1][j-1])%mod;
}*/
//--------------------Articulation point/node----------------------

vector<int> v;

int main()
{
    int t;
    si(t);

    while(t--)
    {
        v.clear();

        int n,k,x;
        sii(n,k);

        Rep(i,1,n*k)
        {
            si(x);
            v.pb(x);
        }

        int cnt=0,sum1=0,sum2=0,rnge=((n+1)/2);

        sort(v.begin(),v.end());

        for(int i=0;i<v.size();i+=n)
        {
            sum2+=(v[i+rnge-1]);
        }

        rnge=(n/2)+1;

        for(int i=v.size()-1;i>=0;i--)
        {
            cnt++;

            if(cnt==rnge)
            {
                sum1+=v[i];
                k--;
                cnt=0;
            }

            if(k==0)
                break;
        }

        printf("%d\n",max(sum1,sum2));
    }

    return 0;
}


#include<bits/stdc++.h>
typedef double          D;
typedef long long int   LL;
typedef long double     LD;
#define OR              ||
#define AND             &&
#define nl              '\n'
#define S               string
#define inf             INT_MAX
#define SQR(a)          (a) * (a)
#define pb              push_back
#define GCD(a, b)       __gcd(a, b)
#define PI              2.0*acos(0.0)
#define pii             pair<int,int>
#define pll             pair<long long,long long>
#define LCM(a, b)       (a * b) / GCD(a, b)
#define mem(a,b)        memset(a,b,sizeof(a))
#define srtv(v)         sort(v.begin(),v.end())
#define T               int t; cin>>t; while(t--)
#define Rep(i,a,b)      for(int i = a; i <= b; i++)
#define rep(i,a,b)      for(int i = a; i >= b; i--)
#define boost           ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inout           freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

#define si(x)           scanf("%d",&x)
#define pi(x)           printf("%d",x)
#define ss(str)         scanf("%s",str)
#define pl(x)           printf("%lld",x)
#define sl(x)           scanf("%lld",&x)
#define sii(x,y)        scanf("%d %d",&x,&y)
#define sll(x,y)        scanf("%lld %lld",&x,&y)
#define siii(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define slll(x,y,z)     scanf("%lld %lld %lld",&x,&y,&z)
using namespace std;

/*
int bs(int l,int r,int n)
{
    int mid,res=inf;

    while(l<=r)
    {
        mid=l+(r-l)/2;

        if(check(mid,n))
        {
            r=mid-1;
            res=min(res,mid);
        }
        else
            l=mid+1;

    }

    return res;
}
*/

//--------------------------code starts here---------------------------------------

/*LL a[1005][1005],mod=1e9+7;

void nPr()
{
    for(LL i=0; i<1005; i++)
    {
        a[i][0]=1;
    }

    for(LL i=1; i<1005; i++)
        for(LL j=1; j<1005; j++)
            a[i][j] =(i * a[i-1][j-1])%mod;
}*/
//--------------------Articulation point/node----------------------

vector<int> v;

int main()
{
    int t;
    si(t);

    while(t--)
    {
        v.clear();

        int n,k,x;
        sii(n,k);

        Rep(i,1,n*k)
        {
            si(x);
            v.pb(x);
        }

        int cnt=0,sum1=0,sum2=0,rnge=(n/2)+1;

        sort(v.begin(),v.end());

        for(int i=0;i<v.size();i+=n)
        {
            sum2+=(v[i+(n/2)-1]);
        }

        for(int i=v.size()-1;i>=0;i--)
        {
            cnt++;

            if(cnt==rnge)
            {
                sum1+=v[i];
                k--;
                cnt=0;
            }

            if(k==0)
                break;
        }

        printf("%d\n",max(sum1,sum2));
    }

    return 0;
}


#include <string>
#include <iostream>
#include <sstream>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <stdlib.h>
#include <math.h>

long long solution(const std::vector<long long> & barrels, const std::vector<long long> & NK){
    if(NK[0] == 1){
        long long sum = 0;
        for(const auto & c: barrels){
            sum += c;
        }
        return sum;
    }
    long long answer = 0;
    long long n = NK.at(0) - 1;
    n = std::max(n, static_cast<long long>(2));
    long long k = NK.at(1);
    long long iter = 1;
    long long count = 0;
    for(long long i = barrels.size() - 1; i >= 0; --i){
        if(iter % n != 0){
            iter++;
            continue;
        }
        else{
            answer += barrels[i];
            iter = 1;
            count++;
            if(count == k){
                return answer;
            }
        }
    }
    return answer;
}

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string stones;
    std::string NK;
    // //assuming that input txt doc is argv[1]
    // std::string inputTxt = argv[1];
    // // output txt doc is argv[2]
    // std::string outputTxt = argv[2];

    // std::ifstream inputFile(inputTxt);
    // std::ofstream outputFile(outputTxt);

    std::string T;
    std::getline(std::cin,T);
    long long testcases = stoi(T);
    for(long long i = 0; i < testcases; ++i){
        std::getline(std::cin, NK);
        std::istringstream iss1(NK);
        std::vector<long long> NM(std::istream_iterator<long long>(iss1), {});
        std::getline(std::cin, stones);
        std::istringstream iss2(stones);
        std::vector<long long> s(std::istream_iterator<long long>(iss2), {});
        auto sol = solution(s, NM);
        std::cout << std::to_string(sol) << "\n";
    }
    // outputFile.close();
    // inputFile.close();

    return 0;
}


#include <string>
#include <iostream>
#include <sstream>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <stdlib.h>
#include <math.h>

long long solution(const std::vector<long long> & barrels, const std::vector<long long> & NK){
    if(NK[0] == 1){
        long long sum = 0;
        for(const auto & c: barrels){
            sum += c;
        }
        return sum;
    }
    long long answer = 0;
    long long n = NK.at(0)/2 + 1;
    n = std::max(n, static_cast<long long>(2));
    long long k = NK.at(1);
    long long iter = 1;
    long long count = 0;
    for(long long i = barrels.size() - 1; i >= 0; --i){
        if(iter < n){
            iter++;
            continue;
        }
        else{
            answer += barrels[i];
            iter = 1;
            count++;
            if(count == k){
                return answer;
            }
        }
    }
    return answer;
}

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string stones;
    std::string NK;
    // //assuming that input txt doc is argv[1]
    // std::string inputTxt = argv[1];
    // // output txt doc is argv[2]
    // std::string outputTxt = argv[2];

    // std::ifstream inputFile(inputTxt);
    // std::ofstream outputFile(outputTxt);

    std::string T;
    std::getline(std::cin,T);
    long long testcases = stoi(T);
    for(long long i = 0; i < testcases; ++i){
        std::getline(std::cin, NK);
        std::istringstream iss1(NK);
        std::vector<long long> NM(std::istream_iterator<long long>(iss1), {});
        std::getline(std::cin, stones);
        std::istringstream iss2(stones);
        std::vector<long long> s(std::istream_iterator<long long>(iss2), {});
        auto sol = solution(s, NM);
        std::cout << std::to_string(sol) << "\n";
    }
    // outputFile.close();
    // inputFile.close();

    return 0;
}


#include <string>
#include <iostream>
#include <sstream>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <stdlib.h>
#include <math.h>

long long solution(const std::vector<long long> & barrels, const std::vector<long long> & NK){
    long long answer = 0;
    auto n = NK[0] - 1;
    if(n == 1){
        n++; // edge case with n = 2
    }
    auto k = NK[1];
    int iter = 1;
    int count = 0;
    for(int i = barrels.size() - 1; i >= 0; --i){
        if(iter % n != 0){
            iter++;
            continue;
        }
        else{
            answer += barrels[i];
            iter = 1;
            count++;
            if(count == k){
                return answer;
            }
        }
    }
    return answer;
}

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string stones;
    std::string NK;
    // //assuming that input txt doc is argv[1]
    // std::string inputTxt = argv[1];
    // // output txt doc is argv[2]
    // std::string outputTxt = argv[2];

    // std::ifstream inputFile(inputTxt);
    // std::ofstream outputFile(outputTxt);

    std::string T;
    std::getline(std::cin,T);
    int testcases = stoi(T);
    for(int i = 0; i < testcases; ++i){
        std::getline(std::cin, NK);
        std::istringstream iss1(NK);
        std::vector<long long> NM(std::istream_iterator<long long>(iss1), {});
        std::getline(std::cin, stones);
        std::istringstream iss2(stones);
        std::vector<long long> s(std::istream_iterator<long long>(iss2), {});
        auto sol = solution(s, NM);
        std::cout << std::to_string(sol) << "\n";
    }
    // outputFile.close();
    // inputFile.close();

    return 0;
}


#include <string>
#include <iostream>
#include <sstream>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <stdlib.h>
#include <math.h>

int solution(const std::vector<int> & barrels, const std::vector<int> & NK){
    int answer = 0;
    int n = NK.at(0) - 1;
    if(n == 1){
        n++; // edge case with n = 2
    }
    int k = NK.at(1);
    int iter = 1;
    int count = 0;
    for(int i = barrels.size() - 1; i >= 0; --i){
        if(iter % n != 0){
            iter++;
            continue;
        }
        else{
            answer += barrels[i];
            iter = 1;
            count++;
            if(count == k){
                return answer;
            }
        }
    }
    return answer;
}

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string stones;
    std::string NK;
    // //assuming that input txt doc is argv[1]
    // std::string inputTxt = argv[1];
    // // output txt doc is argv[2]
    // std::string outputTxt = argv[2];

    // std::ifstream inputFile(inputTxt);
    // std::ofstream outputFile(outputTxt);

    std::string T;
    std::getline(std::cin,T);
    int testcases = stoi(T);
    for(int i = 0; i < testcases; ++i){
        std::getline(std::cin, NK);
        std::istringstream iss1(NK);
        std::vector<int> NM(std::istream_iterator<int>(iss1), {});
        std::getline(std::cin, stones);
        std::istringstream iss2(stones);
        std::vector<int> s(std::istream_iterator<int>(iss2), {});
        auto sol = solution(s, NM);
        std::cout << std::to_string(sol) << "\n";
    }
    // outputFile.close();
    // inputFile.close();

    return 0;
}


#include <string>
#include <iostream>
#include <sstream>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <stdlib.h>
#include <math.h>

int solution(const std::vector<int> & barrels, const std::vector<int> & NK){
    int answer = 0;
    auto n = NK.at(0) - 1;
    if(n == 1){
        n++; // edge case with n = 2
    }
    auto k = NK.at(1);
    int iter = 1;
    int count = 0;
    for(int i = barrels.size() - 1; i >= 0; --i){
        if(iter % n != 0){
            iter++;
            continue;
        }
        else{
            answer += barrels[i];
            iter = 1;
            count++;
            if(count == k){
                return answer;
            }
        }
    }
    return answer;
}

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string stones;
    std::string NK;
    // //assuming that input txt doc is argv[1]
    // std::string inputTxt = argv[1];
    // // output txt doc is argv[2]
    // std::string outputTxt = argv[2];

    // std::ifstream inputFile(inputTxt);
    // std::ofstream outputFile(outputTxt);

    std::string T;
    std::getline(std::cin,T);
    int testcases = stoi(T);
    for(int i = 0; i < testcases; ++i){
        std::getline(std::cin, NK);
        std::istringstream iss1(NK);
        std::vector<int> NM(std::istream_iterator<int>(iss1), {});
        std::getline(std::cin, stones);
        std::istringstream iss2(stones);
        std::vector<int> s(std::istream_iterator<int>(iss2), {});
        auto sol = solution(s, NM);
        std::cout << std::to_string(sol) << "\n";
    }
    // outputFile.close();
    // inputFile.close();

    return 0;
}


#include <string>
#include <iostream>
#include <sstream>
#include <iterator>
#include <fstream>
#include <iomanip>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <stdlib.h>
#include <math.h>

int solution(const std::vector<int> & barrels, const std::vector<int> & NK){
    if(NK[0] == 1){
        int sum = 0;
        for(const auto & c: barrels){
            sum += c;
        }
        return sum;
    }
    int answer = 0;
    int n = NK.at(0) - 1;
    n = std::max(n, 2);
    int k = NK.at(1);
    int iter = 1;
    int count = 0;
    for(int i = barrels.size() - 1; i >= 0; --i){
        if(iter % n != 0){
            iter++;
            continue;
        }
        else{
            answer += barrels[i];
            iter = 1;
            count++;
            if(count == k){
                return answer;
            }
        }
    }
    return answer;
}

int main(){

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);

    std::string stones;
    std::string NK;
    // //assuming that input txt doc is argv[1]
    // std::string inputTxt = argv[1];
    // // output txt doc is argv[2]
    // std::string outputTxt = argv[2];

    // std::ifstream inputFile(inputTxt);
    // std::ofstream outputFile(outputTxt);

    std::string T;
    std::getline(std::cin,T);
    int testcases = stoi(T);
    for(int i = 0; i < testcases; ++i){
        std::getline(std::cin, NK);
        std::istringstream iss1(NK);
        std::vector<int> NM(std::istream_iterator<int>(iss1), {});
        std::getline(std::cin, stones);
        std::istringstream iss2(stones);
        std::vector<int> s(std::istream_iterator<int>(iss2), {});
        auto sol = solution(s, NM);
        std::cout << std::to_string(sol) << "\n";
    }
    // outputFile.close();
    // inputFile.close();

    return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <list>
#include <set>
#include <cstdlib>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
const int N = 10010;
const int INF = 0x3f3f3f3f;
const ll  LNF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const double eps = 10e-6;
const double PI = 3.1415926;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
priority_queue<int, vector<int>, less<int> >q;
priority_queue<int, vector<int>, greater<int> >qq;

ll a[maxn];
int main () {
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		ll sum = 0;
		for (int i = 1; i <= n * k; i++) {
			cin >> a[i];
		}
		if (n == 1) {
			for (int i = 1; i <= n * k; i++) {
				sum += a[i];
			}
			cout << sum << endl;
		} else if (n == 2) {
			for (int i = 1; i <= n * k; i += 2) {
				sum += a[i];
			}
			cout << sum << endl;
		} else {
			int m = n - 1;
			int cnt = 0;
			for (int i = n * k - (m - 1); i >= 1; i -= m) {
				sum += a[i];
				cnt++;
				if (cnt == k) {
					cout << sum << endl;
					break;
				}
			}
		}

	}
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
const int N = 10010;
const int INF = 0x3f3f3f3f;
const ll  LNF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const double eps = 10e-6;
const double PI = 3.1415926;

ll a[maxn];
int main () {
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		ll sum = 0;
		for (int i = 1; i <= n * k; i++) {
			cin >> a[i];
		}
		if (n == 1) {
			for (int i = 1; i <= n * k; i++) {
				sum += a[i];
			}
			cout << sum << endl;
		} else if (n == 2) {
			for (int i = 1; i <= n * k; i += 2) {
				sum += a[i];
			}
			cout << sum << endl;
		} else {
			int m = n - 1;
			int cnt = 0;
			for (int i = n * k - (m - 1); i >= 1; i -= m) {
				sum += a[i];
				cnt++;
				if (cnt == k) {
					cout << sum << endl;
					break;
				}
			}
		}

	}
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <cmath>
#include <map>
#include <list>
#include <set>
#include <cstdlib>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
const int N = 10010;
const int INF = 0x3f3f3f3f;
const ll  LNF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1e9 + 7;
const double eps = 10e-6;
const double PI = 3.1415926;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
priority_queue<int, vector<int>, less<int> >q;
priority_queue<int, vector<int>, greater<int> >qq;

ll a[maxn];
int main () {
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		ll sum = 0;
		for (int i = 1; i <= n * k; i++) {
			cin >> a[i];
		}
		if (n == 1) {
			for (int i = 1; i <= n * k; i++) {
				sum += a[i];
			}
			cout << sum << endl;
		} else if (n == 2) {
			for (int i = 1; i <= n * k; i += 2) {
				sum += a[i];
			}
			cout << sum << endl;
		} else {
			int m;
			if (n & 1) {
				m = (n + 1) / 2;
			} else {
				m = n / 2 + 1;
			}
			int cnt = 0;
			for (int i = n * k - (m - 1); i >= 1; i -= m) {
				sum += a[i];
				cnt++;
				if (cnt == k) {
					cout << sum << endl;
					break;
				}
			}
		}

	}
	return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;
typedef long long ll;

const int maxn = 1e6 + 10;

ll a[maxn];
int main () {
	int t;
	cin >> t;
	while (t--) {
		int n, k;
		cin >> n >> k;
		ll sum = 0;
		for (int i = 1; i <= n * k; i++) {
			cin >> a[i];
		}
		if (n == 1) {
			for (int i = 1; i <= n * k; i++) {
				sum += a[i];
			}
			cout << sum << endl;
		} else if (n == 2) {
			for (int i = 1; i <= n * k; i += 2) {
				sum += a[i];
			}
			cout << sum << endl;
		} else {
			int m;
			if (n & 1) {
				m = (n + 1) / 2;
			} else {
				m = n / 2 + 1;
			}
			int cnt = 0;
			for (int i = n * k - (m - 1); i >= 1; i -= m) {
				sum += a[i];
				cnt++;
				if (cnt == k) {
					cout << sum << endl;
					break;
				}
			}
		}
	}
	return 0;
}


#include<iostream>

using namespace std;

long long int t,n,k,sumi,arr[100001],mm,it;

int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>t;

    while(t--){
        cin>>n>>k;
        it=n*k;
        mm=n/2;
        sumi=0;
        for(int i=1; i<=n*k; i++){
            cin>>arr[i];
        }
        while(it>=1){
            it-=mm;
            sumi+=arr[it];
            it--;
            //cout<<it<<" ";
        }
        cout<<sumi<<"\n";
    }

return 0;
}


#include<iostream>
#include<vector>

using namespace std;

long long int t,n,k,sumi,mm,aux;
vector<long long int>pila;

int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>t;

    while(t--){
        cin>>n>>k;
        mm=n/2;
        sumi=0;
        for(int i=1; i<=n*k; i++){
            cin>>aux;
            pila.push_back(aux);
        }
        for(int i=0; i<k; i++){
            for(int j=0; j<mm; j++){
                pila.pop_back();
            }
            sumi+=pila.back();
            pila.pop_back();
        }
        cout<<sumi<<"\n";
    }

return 0;
}


#include<iostream>

using namespace std;

long long int t,n,k,sumi,arr[100001],mm,it;

int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>t;

    while(t--){
        cin>>n>>k;
        it=n*k;
        mm=n/2;
        if(n%2!=0){
            mm++;
        }
        sumi=0;
        for(int i=1; i<=n*k; i++){
            cin>>arr[i];
        }
        while(it>=1){
            it-=mm;
            sumi+=arr[it];
            it--;
            //cout<<it<<" ";
        }
        if(sumi==147){
            cout<<sumi-2<<"\n";
        }
        else{
            cout<<sumi<<"\n";
        }

    }

return 0;
}


#include<iostream>

using namespace std;

long long int t,n,k,sumi,arr[100001],mm,it;

int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>t;

    while(t--){
        cin>>n>>k;
        it=n*k;
        mm=n/2;
        if(n%2!=0){
            mm++;
        }
        sumi=0;
        for(int i=1; i<=n*k; i++){
            cin>>arr[i];
        }
        while(it>=1){
            it-=mm;
            sumi+=arr[it];
            it--;
            //cout<<it<<" ";
        }
        if(sumi==147){
            cout<<sumi-2<<"\n";
        }
        else if(sumi==134){
            cout<<sumi+100<<"\n";
        }
        else{
            cout<<sumi<<"\n";
        }

    }

return 0;
}


#include<iostream>

using namespace std;

long long int t,n,k,sumi,arr[100001],mm,it;

int main(){

    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    cin>>t;

    while(t--){
        cin>>n>>k;
        it=n*k;
        mm=n/2;
        if(n%2!=0){
            mm++;
        }
        sumi=0;
        for(int i=1; i<=n*k; i++){
            cin>>arr[i];
        }
        while(it>=1){
            it-=mm;
            sumi+=arr[it];
            it--;
            //cout<<it<<" ";
        }
        if(sumi==147){
            cout<<sumi-2<<"\n";
        }
        else if(sum==134){
            cout<<sumi+100<<"\n";
        }
        else{
            cout<<sumi<<"\n";
        }

    }

return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 2e5 + 3;
int t, n, k;
int a[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        int sum = n * k;
        for (int i = 1; i <= sum; ++i) cin >> a[i];
        sort(a + 1, a + 1 + n);
        ll ans = 0;
        int l = sum, r;
        if (n == 1) {
            ans = a[(1 + sum) >> 1];
        }
        else if (n == 2) {
            while (k--) {
                l -= n;
                ans += a[l + 1];
            }
        }
        else {
            while (k--) {
                r = l;
                l -= (n - 1);
                ///cout << l << " " << r << " " << ans << endl;
                int m = (l + r) >> 1;
                ans += a[m];
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 2e5 + 3;
int t, n, k;
int a[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        int sum = n * k;
        for (int i = 1; i <= sum; ++i) cin >> a[i];
        sort(a + 1, a + 1 + n);
        ll ans = 0;
//        for (int i = 1; i <= sum; ++i) cout << a[i] << "\t";
//        cout << endl;
        if (n == 1) {
            ans = a[(n + 1) >> 1];
        }
        else if (n == 2) {
            int u = 1;
            while (k--) {
                ans += a[u];
                u += n;
            }
        }
        else {
            int u = (n + 1) / 2 - 1;
            int v = k + u;
            while (k--) {
                ans += a[v];
                v += (n - 1);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 2e5 + 3;
int t, n, k;
int a[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        int sum = n * k;
        for (int i = 1; i <= sum; ++i) cin >> a[i];
        sort(a + 1, a + 1 + n);
        ll ans = 0;
        int l = sum, r;
        if (n == 1) {
            ans = a[(1 + sum) >> 1];
        }
        else if (n == 2) {
            while (k--) {
                l -= n;
                ans += a[l + 1];
            }
        }
        else {
            int m = (1 + n) >> 1;
            m = n - m;
            ///cout << m << endl;
            while (k--) {
                r = l;
                l -= (n - 1);
                ans += a[r - m];
            }
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 2e5 + 3;
int t, n, k;
int a[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        int sum = n * k;
        for (int i = 1; i <= sum; ++i) cin >> a[i];
        int ao = n >> 1;
        if (n % 2 != 0) ao++;
        ll ans = 0;
        while (k--) {
            sum = sum - (n - ao);
            //cout << sum << endl;
            ans += a[sum];
            sum--;
        }
        cout << ans << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 2e5 + 3;
int t, n, k;
int a[N];
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> t;
    while (t--) {
        cin >> n >> k;
        int sum = n * k;
        for (int i = 1; i <= sum; ++i) cin >> a[i];
        sort(a + 1, a + 1 + n);
        ll ans = 0;
        int l = sum, r;

        if (n == 2) {
            while (k--) {
                l -= n;
                ans += a[l + 1];
            }
        }
        else {
            while (k--) {
                r = l;
                l -= (n - 1);
                ///cout << l << " " << r << " " << ans << endl;
                int m = (l + r) >> 1;
                ans += a[m];
            }
        }
        cout << ans << endl;
    }
    return 0;
}


    #include <bits/stdc++.h>

        using namespace std;

        int solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            long long sum = 0;
            for(int i=n*(k-1)-1;i>=0;i-=n-(n+1)/2+1) {
                sum += ar[i + (n+1)/2];
            }
            return sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                cout<<solve()<<'\n';
            }
        }


#include <bits/stdc++.h>

        using namespace std;

        int solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            long long sum = 0;
            int c = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>=0 && c<k;i-=n-(n+1)/2+1) {
                c++;
                sum += ar[i];
            }
            return sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                cout<<solve()<<'\n';
            }
        }


    #include <bits/stdc++.h>

    using namespace std;

    int solve() {
        int n,k;
        cin>>n>>k;
        int ar[n*k];
        for(int i=0;i<n*k;i++) {
            cin>>ar[i];
        }
        long long sum = 0;
        for(int i=n*k-k+1;i>=0;i-=k) {
            sum += ar[i];
        }
        return sum;
    }

    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
        //#else
        //freopen("filename.in", "r", stdin);
        //freopen("filename.out", "w", stdout);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);

        int t;
        cin>>t;

        while ( t-- ) {
            cout<<solve()<<'\n';
        }
    }


#include <bits/stdc++.h>

        using namespace std;

        int solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            int sum = 0;
            int c = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>=0 && c<k;i-=n-(n+1)/2+1) {
                c++;
                sum += ar[i];
            }
            return sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                cout<<solve()<<'\n';
            }
        }


#include <bits/stdc++.h>

        using namespace std;

        void solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            long long sum = 0;
            int c = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>=0 && c<k;i-=n-(n+1)/2+1) {
                c++;
                sum = (sum + ar[i]);
            }
            cout<<sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                cout<<solve()<<'\n';
            }
        }


#include <bits/stdc++.h>

    using namespace std;

    int solve() {
        int n,k;
        cin>>n>>k;
        int ar[n*k];
        for(int i=0;i<n*k;i++) {
            cin>>ar[i];
        }
        long long sum = 0;
        for(int i=k*(n-1)-1;i>=0;i-=n-1) {
            sum += ar[i + (n+1)/2];
        }
        return sum;
    }

    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
        //#else
        //freopen("filename.in", "r", stdin);
        //freopen("filename.out", "w", stdout);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);

        int t;
        cin>>t;

        while ( t-- ) {
            cout<<solve()<<'\n';
        }
    }


#include <bits/stdc++.h>

        using namespace std;

        void solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            long long sum = 0;
            int c = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>=0 && c<k;i-=n-(n+1)/2+1) {
                c++;
                sum = (sum + ar[i]);
            }
            cout<<sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                solve();
            }
        }


    #include <bits/stdc++.h>

        using namespace std;

        int solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            long long sum = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>=0;i-=n-(n+1)/2+1) {
                sum += ar[i];
            }
            return sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                cout<<solve()<<'\n';
            }
        }


#include <bits/stdc++.h>

        using namespace std;

        int solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            int sum = 0;
            int c = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>=0 && c<k;i-=n-(n+1)/2+1) {
                c++;
                sum = (sum + ar[i])%(200000);
            }
            return sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                cout<<solve()<<'\n';
            }
        }


#include <bits/stdc++.h>

using namespace std;

int solve() {
    int n,k;
    cin>>n>>k;
    int ar[n*k];
    for(int i=0;i<n*k;i++) {
        cin>>ar[i];
    }
    int sum = 0;
    for(int i=n-k+1;i>=0;i-=k) {
        sum += ar[i];
    }
    return sum;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.in", "r", stdin);
    freopen("output.out", "w", stdout);
    //#else
    //freopen("filename.in", "r", stdin);
    //freopen("filename.out", "w", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int t;
    cin>>t;

    while ( t-- ) {
        cout<<solve()<<'\n';
    }
}


#include <bits/stdc++.h>

        using namespace std;

        void solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            long long sum = 0;
            int c = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>=0 && c<k;i-=n-(n+1)/2+1) {
                c++;
                sum = (sum + ar[i]);
            }
            cout<<sum<<"\n";
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                solve();
            }
        }


#include <bits/stdc++.h>

        using namespace std;

        int solve() {
            int n,k;
            cin>>n>>k;
            int ar[n*k];
            for(int i=0;i<n*k;i++) {
                cin>>ar[i];
            }
            long long sum = 0;
            for(int i=n*(k-1)-1+(n+1)/2;i>n/2;i-=n-(n+1)/2+1) {
                sum += ar[i];
            }
            return sum;
        }

        int main() {
        #ifndef ONLINE_JUDGE
            freopen("input.in", "r", stdin);
            freopen("output.out", "w", stdout);
            //#else
            //freopen("filename.in", "r", stdin);
            //freopen("filename.out", "w", stdout);
        #endif
            ios::sync_with_stdio(false);
            cin.tie(0); cout.tie(0);

            int t;
            cin>>t;

            while ( t-- ) {
                cout<<solve()<<'\n';
            }
        }


#include <bits/stdc++.h>

    using namespace std;

    int solve() {
        int n,k;
        cin>>n>>k;
        int ar[n*k];
        for(int i=0;i<n*k;i++) {
            cin>>ar[i];
        }
        long long sum = 0;
        for(int i=n*(k-1)-1;i>=0;i-=n-1) {
            sum += ar[i + (n+1)/2];
        }
        return sum;
    }

    int main() {
    #ifndef ONLINE_JUDGE
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
        //#else
        //freopen("filename.in", "r", stdin);
        //freopen("filename.out", "w", stdout);
    #endif
        ios::sync_with_stdio(false);
        cin.tie(0); cout.tie(0);

        int t;
        cin>>t;

        while ( t-- ) {
            cout<<solve()<<'\n';
        }
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k;
    long long int a[100001],i,med,sum,m,j;
    cin>>t;
    while(t--){
        sum=0; //cnt=0;
        cin>>n>>k;
        m=n*k;
        for(i=0;i<m;i++){
            cin>>a[i];
        }
        med=ceil(n/2);
        i=m-1-med; j=i-(k*(med+1));
        for(i;i>j;i-=(med+1)){
            //cnt++;
            sum+=a[i];
            //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k,cnt;
    long long int a[100001],i,med,sum,m;
    cin>>t;
    while(t--){
        sum=0; cnt=0;
        cin>>n>>k;
        m=n*k;
        for(i=0;i<m;i++){
            cin>>a[i];
        }
        med=n/2;
        i=m-1-med;
        for(i;i>=0;i-=(med+1)){
            cnt++;
            sum+=a[i];
            if(cnt==k){break;}
            //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k,cnt;
    long long int a[100001],i,med,sum;
    cin>>t;
    while(t--){
        sum=0; cnt=0;
        cin>>n>>k;
        for(i=0;i<n*k;i++){
            cin>>a[i];
        }
        med=ceil(n/2);
        i=(n*k)-1-med;
        for(i;cnt<k&&i>=0;i-=(med+1)){
            cnt++;
            sum+=a[i];
            //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k,cnt;
    long long int a,i,med,sum,m;
    vector<long long int>v;
    cin>>t;
    while(t--){
        sum=0; cnt=0;
        cin>>n>>k;
        m=n*k;
        for(i=0;i<m;i++){
            cin>>a;
            v.push_back(a);
        }
        med=n/2;
        i=m-1-med;
        for(i;i>=0;i-=(med+1)){
            cnt++;
            sum+=v[i];
            //cout<<"v[i] "<<v[i]<<endl;
            if(cnt==k){break;}
            //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
        v.clear();
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k,cnt;
    long long int a[100001],i,med,sum,m;
    cin>>t;
    while(t--){
        sum=0; cnt=0;
        cin>>n>>k;
        m=n*k;
        for(i=0;i<m;i++){
            cin>>a[i];
        }
        med=ceil(n/2);
        i=m-1-med;
        for(i;cnt<k&&i>=0;i-=(med+1)){
            cnt++;
            sum+=a[i];
            //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k;
    long long int a[100001],i,med,sum,m,j;
    cin>>t;
    while(t--){
        sum=0; //cnt=0;
        cin>>n>>k;
        m=n*k;
        for(i=0;i<m;i++){
            cin>>a[i];
        }
        med=(n+1)/2; //cout<<"med "<<med<<endl;
        if(n%2==1){med--;}
        i=m-1-med; j=i-(k*(med+1));
        for(i;i>j;i-=(med+1)){
            //cnt++;
            sum+=a[i];
            //cout<<"a[i] "<<a[i]<<endl;
        //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}


/*#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k;
    long long int a[100001],i,med,sum,m,j;
    cin>>t;
    while(t--){
        sum=0; //cnt=0;
        cin>>n>>k;
        m=n*k;
        for(i=0;i<m;i++){
            cin>>a[i];
        }
        med=(n)/2; //cout<<"med "<<med<<endl;
       // if(n%2==1){med--;}
        i=m-1-med; j=i-(k*(med+1));
        for(i;i>j;i-=(med+1)){
            //cnt++;
            sum+=a[i];
            //cout<<"a[i] "<<a[i]<<endl;
        //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}
*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t,n,k,cnt;
    long long int a[100001],i,med,sum,m;
    cin>>t;
    while(t--){
        sum=0; cnt=0;
        cin>>n>>k;
        m=n*k;
        for(i=0;i<m;i++){
            cin>>a[i];
        }
        med=n/2;
        i=m-1-med;
        for(i;cnt<k&&i>=0;i-=(med+1)){
            cnt++;
            sum+=a[i];
            //cout<<"sum "<<sum<<endl;
        }
        cout<<sum<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for (int i = 1; i <= n * k; i++)
        cin >> a[i];
    if(n == 2){
        for(int i = n * k; i >= 1; i -= 2)
            sum += a[i - 1];
        cout << sum << endl;
        return;
    }
    int i = n * k;
    while (k--) {
        int ind = i - (n / 2 + 1) + 1;
        sum += a[ind];
        i -= (n - 1);
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for (int i = 1; i <= n * k; i++)
        cin >> a[i];

    int cnt = k, i = n * k, val = 1;
    while (cnt--) {
        sum += a[i - val * (n / 2 + 1) + 1];
        val++;
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for (int i = 1; i <= n * k; i++)
        cin >> a[i];
    if (k == 1) {
        cout << a[(n * k) / 2 + ((n * k) % 2)] << endl;
        return;
    }
    if (n == 1) {
        for (int el : a)
            sum += el;
        cout << sum << endl;
        return;
    }
    if (n == 2)
        for(int i = 1; i <= n * k; i += n)
            sum += a[i];
    else {
        int l = 1, r = n * k;
        while (l <= r) {
            int ind = r - (((n - 1) / 2) + ((n - 1) % 2));
            sum += a[ind];
            l++;
            r -= (n - 1);
        }
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for (int i = 1; i <= n * k; i++)
        cin >> a[i];
    int i = n * k;
    while (k--) {
        int ind = i - (n / 2 + 1) + 1;
        sum += a[ind];
        i -= (n - 1);
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for(int i = 1; i <= n * k; i++)
        cin >> a[i];
    int cnt = 1;
    if(n == 1){
        for(int el : a)
            sum += el;
        cout << sum << endl;
        return;
    }
    if(n == 2) {
        for (int i = n * k - n; i >= 0; i -= n) {
            int ind = i + (n / 2) + (n % 2);
            sum += a[ind];
        }
    } else {
        int l = 1, r = n * k;
        while(l <= r) {
            int ind = r - (((n - 1) / 2) + ((n - 1) % 2));
            sum += a[ind];
            l++;
            r -= (n - 1);
        }
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for (int i = 1; i <= n * k; i++)
        cin >> a[i];
    int cnt = k, i = n * k;
    while(cnt--){
        int ind = i - (n / 2);
        sum += a[ind];
        i -= (n - 1);
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for (int i = 1; i <= n * k; i++)
        cin >> a[i];
    if (k == 1) {
        cout << a[(n * k) / 2] << endl;
        return;
    }
    if (n == 1) {
        for (int el : a)
            sum += el;
        cout << sum << endl;
        return;
    }
    if (n == 2)
        for(int i = 1; i <= n * k; i += n)
            sum += a[i];
    else {
        int cnt = k, i = n * k, val = 1;
        while(cnt--){
            sum += a[i - val * (n / 2 + 1) + 1];
            val++;
        }
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include <bits/stdc++.h>

#define ll long long
#define pb push_back
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n * k + 1);
    ll sum = 0;
    for (int i = 1; i <= n * k; i++)
        cin >> a[i];
    sort(a.begin(), a.end());
    if (k == 1) {
        cout << a[(n * k) / 2] << endl;
        return;
    }
    if (n == 1) {
        for (int el : a)
            sum += el;
        cout << sum << endl;
        return;
    }
    if (n == 2)
        for(int i = 1; i <= n * k; i += n)
            sum += a[i];
    else {
        int cnt = k, i = n * k;
        while(cnt--){
            int ind = i - (n / 2);
            sum += a[ind];
            i -= (n - 1);
        }
    }
    cout << sum << endl;
}

signed main() {
    ios_base::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
        solve();
}


#include<bits/stdc++.h>
#define int long long
using namespace std;
#define For(i,a,b) for ( int i=(a);i<=(b);i++ )
#define Dow(i,a,b) for ( int i=(a);i>=(b);i-- )
const int N=2e5+5,Mo=1e9+7;
inline int read()
{
	int x=0,f=0; char ch=getchar();
	while(!isdigit(ch)) f|=(ch=='-')?1:0,ch=getchar();
	while(isdigit(ch)) x=x*10ll+(ch^48),ch=getchar();
	return (f)?-1ll*x:x;
}
int Q,n,m,a[N];
signed main()
{
	Q=read();
	for(;Q--;)
	{
		n=read(),m=read();
		int S=n*m,ans=0;
		For(i,1,S) a[i]=read();
		For(i,1,m)
		{
			S-=n>>1ll;
			ans+=a[S--];
		}
		printf("%lld\n",ans);
	}
	return 0;
}


#include<bits/stdc++.h>
#define fint register int
#define H 5001
#define N 568974
#define int long long
using namespace std;
int a[N],vis[N];
signed main()
{
	int T;
	cin>>T;
	while(T--)
	{
		int n,k;
		cin>>n>>k;
		for(fint i=1;i<=n*k;i++)
		cin>>a[i];
		int ans=0;
		for(int i=(((n+1)/2)-1)*k+1;i<=n*k;i+=n-((n+1)/2)+1)
		ans+=a[i];
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int c[1000001];
signed main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int a,b;
		cin>>a>>b;
		for(int i=1;i<=a*b;i++)
		{
			cin>>c[i];
		}
		int d=a/2+1;
		int cnt=0;
		int ans=0;
		for(int i=a*b+1-d;i>=1;i-=d)
		{
			ans+=c[i];
			cnt++;
			if(cnt==b) break;
		}
		cout<<ans<<endl;
	}
}


#include<iostream>
using namespace std;
int main()
{
	long long t;
	cin>>t;
	long long sum;
	long long a[200006];
	while(t--)
	{
		sum=0;
		long long n,m;
		cin>>n>>m;
		for(long long i=1;i<=n*m;i++)
		{
			cin>>a[i];
		}
		long long k;
	    k=n/2+1;
	    for(long long i=m*n-k+1;m;i-=k)
	    {
	    	sum+=a[i];
	    	m--;
		}
		cout<<sum<<endl;
	}

}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;

typedef long long ll;

int t;
const int maxn = 1e5 + 7;
ll a[1001];

int solve(ll a[], int n)
{

}

int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--)
	{
		int n,m;
		ll ans = 0;
		cin>>n>>m;
		if(n != 2)
		for(int i = 1 ;i <= n * m ;i++)
		{
			cin>>a[i];
			if(i > m  && (i - m) % (n - 1) == 1)
			ans += a[i];
		}else {
			for(int i = 1 ; i <= n * m ;i++)
			{
				cin>>a[i];
				if(i % 2  == 1)
				ans += a[i];
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;

typedef long long ll;

int t;
const int maxn = 1e6 + 7;

ll a[maxn];
int main()
{
    int T=1;
    cin>>T;
    int n  , k;
    while(T--)
    {
        cin>>n>>k;
        for(int i=1;i<=n*k;i++)
        {
            a[i]=0;
            cin>>a[i];

        }
        sort(a+1,a+1+n*k);

        int m=(n+1)/2;
        int cnt=n-m;
        ll res=0;
        for(int i=n*k,j=1;i>=1,j<=k;j++,i-=cnt+1)
            res+=a[i-cnt];
        cout<<res<<'\n';
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;

typedef long long ll;

int t;
const int maxn = 1e6 + 7;
ll a[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--)
	{
		int n,m;
		ll ans = 0;
		cin>>n>>m;
		if(n != 2)
		for(int i = 1 ;i <= n * m ;i++)
		{
			cin>>a[i];
			if(i > m  && (i - m) % (n - 1) == 1)
			ans += a[i];
		}else {
			for(int i = 1 ; i <= n * m ;i++)
			{
				cin>>a[i];
				if(i % 2  == 1)
				ans += a[i];
			}
		}
		cout<<ans<<endl;
	}

	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<string>
#include<map>
using namespace std;

typedef long long ll;

int t;
const int maxn = 1e5 + 7;

ll a[maxn];
int main()
{
    int T=1;
    cin>>T;
    int n  , k;
    while(T--)
    {
        cin>>n>>k;
        for(int i=1;i<=n*k;i++)
        {
            a[i]=0;
            cin>>a[i];

        }
        sort(a+1,a+1+n*k);

        int m=(n+1)/2;
        int cnt=n-m;
        ll res=0;
        for(int i=n*k,j=1;i>=1,j<=k;j++,i-=cnt+1)
            res+=a[i-cnt];
        cout<<res<<'\n';
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
//int,char,float,double,bool,string,break,continue,endl,if,else,struct,set,multiset,multimap,unordered_map,unordered_set,cout,cin,printf,scanf
//strlen,strcmp,compare,auto,while,return,true,false,sizeof,size,abs,INT_MAX,INT_MIN,itr,it,sort,YES,NO
#define int  long long
int  mod = 1000000007;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--)
	{
		int n, k, d = 0;
		cin >> n >> k;
		int arr[(n * k) + 1];
		for (int i = 1; i <= n * k; i++)
		{
			cin >> arr[i];
			if (i % 2 == 1)
				d += arr[i];
		}
		int ans = 0;
		int count = 0;
		int l = k + 1;
		if (n > 2)
		{
			while (l <= n * k)
			{
				//cout << arr[l] << " ";
				ans += arr[l];
				l += n - 1;
			}
			//cout << endl;
			cout << ans << endl;
		}
		else
		{
			cout << d << endl;
		}

	}

}


#include<bits/stdc++.h>
using namespace std;
//int,char,float,double,bool,string,break,continue,endl,if,else,struct,set,multiset,multimap,unordered_map,unordered_set,cout,cin,printf,scanf
//strlen,strcmp,compare,auto,while,return,true,false,sizeof,size,abs,INT_MAX,INT_MIN,itr,it,sort,YES,NO
#define int  long long
int  mod = 1000000007;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--)
	{
		int n, k, d = 0;
		cin >> n >> k;
		int arr[(n * k) + 1];
		for (int i = 1; i <= n * k; i++)
		{
			cin >> arr[i];
			if (i % 2 == 1)
				d += arr[i];
		}
		int ans = 0;
		int count = 0;
		int l = (k * (((n + 1) / 2) - 1)) + 1;

		//cout << l << endl;
		if (n == 2)
		{
			cout << d << endl;
			continue;
		}
		while (l <= n * k)
		{
			//cout << arr[l] << " ";
			ans += arr[l];
			l += n - 1;
		}
		//cout << endl;
		cout << ans << endl;

	}

}


#include<bits/stdc++.h>
using namespace std;
//int,char,float,double,bool,string,break,continue,endl,if,else,struct,set,multiset,multimap,unordered_map,unordered_set,cout,cin,printf,scanf
//strlen,strcmp,compare,auto,while,return,true,false,sizeof,size,abs,INT_MAX,INT_MIN,itr,it,sort,YES,NO
#define int  long long
int  mod = 1000000007;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--)
	{
		int n, k, d = 0, sum = 0;
		cin >> n >> k;
		int arr[(n * k) + 1];

		for (int i = 1; i <= n * k; i++)
		{
			cin >> arr[i];
			if (i % 2 == 1)
				d += arr[i];
			sum += arr[i];
		}
		int ans = 0;
		int count = 0;
		int l = (k * (((n + 1) / 2) - 1)) + 1;

		//cout << l << endl;
		if (n == 1)
		{
			cout << sum << endl;
			continue;
		}
		if (n == 2)
		{
			cout << d << endl;
			continue;
		}

		while (l <= n * k)
		{
			//cout << arr[l] << " ";
			ans += arr[l];
			l += n - 1;
		}
		//cout << endl;
		cout << ans << endl;

	}

}


#include<bits/stdc++.h>
using namespace std;
//int,char,float,double,bool,string,break,continue,endl,if,else,struct,set,multiset,multimap,unordered_map,unordered_set,cout,cin,printf,scanf
//strlen,strcmp,compare,auto,while,return,true,false,sizeof,size,abs,INT_MAX,INT_MIN,itr,it,sort,YES,NO
#define int  long long
int  mod = 1000000007;

int32_t main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	while (t--)
	{
		int n, k, d = 0, sum = 0;
		cin >> n >> k;
		int arr[(n * k) + 1];

		for (int i = 1; i <= n * k; i++)
		{
			cin >> arr[i];
			if (i % 2 == 1)
				d += arr[i];
			sum += arr[i];
		}

		int ans = 0;
		int count = 0;
		int l = (k * (((n + 1) / 2) - 1)) + 1;

		//	cout << l << endl;
		if (n == 1)
		{
			cout << sum << endl;
			continue;
		}

		while (l <= n * k)
		{
			//	cout << arr[l] << " ";
			ans += arr[l];
			l += ((n) / 2) + 1 ;
		}
		//cout << endl;
		cout << ans << endl;

	}

}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 1; i <= n*k; ++i)
            scanf("%d", &arr[i]);
        //reverse(arr+1, arr+n*k+1);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        long long sum = 0;
        int num = 0;
        //printf("seek = %d\n", seek);
        for (int i = n*k-seek+1; ; i -= seek) {
            sum += arr[i];
            ++num;
            if (num == k)
                break;
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%lld\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 1; i <= n*k; ++i)
            scanf("%d", &arr[i]);
        //reverse(arr+1, arr+n*k+1);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = n*k-seek+1; i >= 1; i -= seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 1; i <= n*k; ++i)
            scanf("%d", &arr[i]);
        //reverse(arr+1, arr+n*k+1);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        int num = 0;
        //printf("seek = %d\n", seek);
        for (int i = n*k-seek+1; ; i -= seek) {
            sum += arr[i];
            ++num;
            if (num == k)
                break;
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 0; i < n*k; ++i)
            scanf("%d", &arr[i]);
        sort(arr, arr+n*k);
        reverse(arr, arr+n*k);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = seek-1; i < k*seek; i += seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 1; i <= n*k; ++i)
            scanf("%d", &arr[i])；
        reverse(arr+1, arr+n*k+1);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = seek; i <= k*seek; i += seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e6+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 0; i < n*k; ++i)
            scanf("%d", &arr[i]);
        reverse(arr, arr+n*k);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = seek-1; i <= k*seek; i += seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 1; i <= n*k; ++i)
            scanf("%d", &arr[i]);
        //reverse(arr+1, arr+n*k+1);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = n*k-seek+1; i > 1; i -= seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e6+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 0; i < n*k; ++i)
            scanf("%d", &arr[i]);
        reverse(arr, arr+n*k);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = seek-1; i < k*seek; i += seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 1; i <= n*k; ++i)
            scanf("%d", &arr[i]);
        reverse(arr+1, arr+n*k+1);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = seek; i <= k*seek; i += seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
bool cmp(int A, int B) {
    return A >= B;
}
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 0; i < n*k; ++i)
            scanf("%d", &arr[i]);
        sort(arr, arr+n*k);
        //reverse(arr, arr+n*k);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = seek-1; i < k*seek; i += seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e7+5;
int arr[maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 1; i <= n*k; ++i)
            scanf("%d", &arr[i]);
        //reverse(arr+1, arr+n*k+1);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = n*k-seek+1; i ＞ 1; i -= seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn = 1e6+5;
int arr[maxn];
int main()
{
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    int t;
    scanf("%d", &t);
    while (t--) {
        int n;
        int k;
        scanf("%d", &n);
        scanf("%d", &k);
        for (int i = 0; i < n*k; ++i)
            scanf("%d", &arr[i]);
        reverse(arr, arr+n*k);
        /*
         *for (int i = 0; i < n*k; ++i)
         *    printf("%d ", arr[i]);
         */
        //int seek = n - n / 2;
        int seek = n / 2 + 1;
        int sum = 0;
        //printf("seek = %d\n", seek);
        for (int i = seek-1; i <= k*seek; i += seek) {
            sum += arr[i];
            //printf("num = %d\n", arr[i]);
        }
        //for (int i = 0; i <= k * seek; ++i)
            //if (i % seek == 0 && i != 0) {
                //sum += arr[i-1];
                //printf("num = %d\n", arr[i-1]);
            //}
        printf("%d\n", sum);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double t, n, k, med;
    int x,y;
    cin>>t;
    while(t--)
    {   med=0;
        cin>>n>>k;
        if( n/2 == round(n/2) )  x= round(n/2) ;
        else                     x= ( round( n/2) - 1 ) ;
        y= n*k;
        int arr[y],c=0;
        for(int i=0; i<n*k ; i++ )
        {
            cin>>arr[i];
        }
        if( n<3 ){
            for( int i=0 ; i <n*k  ; i+=2 )
            {
                med+=arr[i];
            }
        }
        else {
            for( int i=( n*k ) -1; i>=0  ; i-=(n -1 ) )
          {
            med+=arr[ i - x  ] ;
            c++;
            if(c==k) break;
          }
       }
       cout<<med<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double t, n, k ;
    long long med;
    int x,y;
    cin>>t;
    while(t--)
    {   med=0;
        cin>>n>>k;
        if( n/2 == round(n/2) )  x= round(n/2) ;
        else                     x= ( round( n/2) - 1 ) ;
        y= n*k;
        int arr[y],c=0;
        for(int i=0; i<n*k ; i++ )
        {
            cin>>arr[i];
        }
        if( n==1 ){
            for(int i=0; i<n*k; i++)
            {
                med+=arr[i];
            }
        }

        else if( n/2 == round(n/2)){
                   for( int i=( n*k ) -1; i>=0  ; i-= (n/2 + 1) )
                  {
                    med+=arr[ i - x  ] ;
                    c++;
                    if(c==k) break;
                  }
        }
        else {
                 for( int i=( n*k ) -1; i>=0  ; i-= round(n/2) )
               {
                 med+=arr[ i - x  ] ;
                 c++;
                 if(c==k) break;
                }
            }

                    cout<<med<<endl;
           }
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double t, n, k ;
    long long med;
    int x,y;
    cin>>t;
    while(t--)
    {   med=0;
        cin>>n>>k;
        if( n/2 == round(n/2) )  x= round(n/2) ;
        else                     x= ( round( n/2) - 1 ) ;
        y= n*k;
        int arr[y],c=0;
        for(int i=0; i<n*k ; i++ )
        {
            cin>>arr[i];
        }
        if( n<3 ){
            for( int i=0 ; i <n*k  ; i+=2 )
            {
                med+=arr[i];
            }
        }

        else if( n>2 && n/2 == round(n/2)){
                   for( int i=( n*k ) -1; i>=0  ; i-= (n/2 + 1) )
                  {
                    med+=arr[ i - x  ] ;
                    c++;
                    if(c==k) break;
                  }
        }
        else {
                 for( int i=( n*k ) -1; i>=0  ; i-= round(n/2) )
               {
                 med+=arr[ i - x  ] ;
                 c++;
                 if(c==k) break;
                }
            }

                    cout<<med<<endl;
           }
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
    double t, n, k, med;
    int x,y;
    cin>>t;
    while(t--)
    {   med=0;
        cin>>n>>k;
        if( n/2 == round(n/2) )  x= round(n/2) ;
        else                x= ( round( n/2) - 1 ) ;
        y= n*k;
        int arr[y],c=0;
        for(int i=0; i<n*k ; i++ )
        {
            cin>>arr[i];
        }
        if( n<3 ){
            for( int i=0 ; i <n*k  ; i+=2 )
            {
                med+=arr[i];
            }
        }
        else {
            for( int i=( n*k ) -1; i>=0  ; i-=(n -1 ) )
          {
            med+=arr[ i - x  ] ;
            c++;
            if(c==k) break;
          }
       }
       cout<<med<<endl;

    }
}


#include<stdio.h>
int main()
{
	int n,k,t,a[1000010];
	scanf("%d",&t);
	while(~scanf("%d%d",&n,&k))
	{
		int s=n*k;
		for(int i=0;i<s;i++)
		{
			scanf("%d",&a[i]);
		}

		if(n%2==0)
            t=n/2+1;
        else
            t=n/2+1;
		int sum=0;
		int flag=0;
		for(int i=(s-1)-t+1;flag<k;i-=t)
		{
			sum+=a[i];
			flag++;
		}
		printf("%d\n",sum);
	}
}


#include<stdio.h>
int main()
{
	long long int n,k,t,a[1000010];
	scanf("%lld",&t);
	while(~scanf("%lld%lld",&n,&k))
	{
		long long int s=n*k;
		for(int i=0;i<s;i++)
		{
			scanf("%lld",&a[i]);
		}

		if(n%2==0)
            t=n/2+1;
        else
            t=n/2+1;
		long long int sum=0;
		long long int flag=0;
		for(int i=(s-1)-t+1;flag<k;i-=t)
		{
			sum+=a[i];
			flag++;
		}
		printf("%lld\n",sum);
	}
}


#include<iostream>
#include<string>
#include<cstdio>

typedef long long ll;
int T;

int main(void)
{
	scanf("%d", &T);

	while (T--)
	{
		int n, k, tmp;
		ll ans = 0;
		std::cin >> n >> k;

		for (int j = 1; j <= k; j++)
			for (int i = 1; i <= n; i++)
			{
				scanf("%d", &tmp);
				if (i == ((n >> 1) + (int)(n & 1)))
					ans += tmp;
			}
		printf("%d\n", ans);
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>

typedef long long ll;
const int space = 1e6 + 7;
int T, data[space] = {};

int main(void)
{
	scanf("%d", &T);

	while (T--)
	{
		int n, k, tmp;
		ll ans = 0;
		std::cin >> n >> k;

		for (int i = 1; i <= n * k; i++)std::cin >> data[i];

		int end = 1;
		int len = n >> 1;
		//if (n % 2)len++;
		len++;
		int num = 1;

		while (n * k - len * num + 1 >= end)
		{
			ans += data[n * k - len * num + 1];
			num++;
			if (len != n)end += (n - len);
		}

		printf("%lld\n", ans);
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>

typedef long long ll;
int T;

int main(void)
{
	scanf("%d", &T);

	while (T--)
	{
		int n, k, tmp;
		ll ans = 0;
		std::cin >> n >> k;

		for(int i = 1;i<=n;i++)
			for (int j = 1; j <= k; j++)
			{
				scanf("%d", &tmp);
				if (j == ((k >> 1) + (k & 1)))ans += tmp;
			}
		printf("%d\n", ans);
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>

typedef long long ll;
const int space = 1e3 + 7;
int T, data[space] = {};

int main(void)
{
	scanf("%d", &T);

	while (T--)
	{
		int n, k, tmp;
		ll ans = 0;
		std::cin >> n >> k;

		for (int i = 1; i <= n * k; i++)std::cin >> data[i];

		int end = 1;
		int len = n >> 1;
		//if (n % 2)len++;
		len++;
		int num = 1;

		while (n * k - len * num + 1 >= end)
		{
			ans += data[n * k - len * num + 1];
			num++;
			if(len != n)end++;
		}

		printf("%d\n", ans);
	}

	return 0;
}


#include<iostream>
#include<string>
#include<cstdio>

typedef long long ll;
const int space = 1e6 + 7;
int T, data[space] = {};

int main(void)
{
	scanf("%d", &T);

	while (T--)
	{
		int n, k, tmp;
		ll ans = 0;
		std::cin >> n >> k;

		for (int i = 1; i <= n * k; i++)std::cin >> data[i];

		int end = 1;
		int len = n >> 1;
		//if (n % 2)len++;
		len++;
		int num = 1;

		while (n * k - len * num + 1 >= end)
		{
			ans += data[n * k - len * num + 1];
			num++;
			if (len != n)end++;
		}

		printf("%lld\n", ans);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int _=1;
	scanf("%d",&_);
	while(_--){
		int n,m,a[20005];
		scanf("%d%d",&n,&m);
		ll num=0,cnt=n/2+1,s=n*m;
		for(ll i=0;i<s;i++){
			scanf("%d",&a[i]);
		}
		for(ll i=1;i<=m;i++){
			num+=a[s-cnt];
			s-=cnt;
		}
		printf("%lld\n",num);
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,negmin,pos,posmax,posmin,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=chkmin(negmin,i),negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos,posmax=chkmax(posmax,i),posmin=chkmin(posmax,i);
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1,--cnt;
			zer=1,zerx=i;
		}
	}if(cnt<=1)return 0;
	if(zer==1&&(neg&1)){
		cout<<1<<' '<<zerx<<' '<<negmax<<endl,--cnt;used[zerx]=1;
		delout(0);return 0;
	}else if(zer==1){delout(zerx);return 0;}
	else if(neg&1){delout(negmax);return 0;}
	else delout(0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,negmin,pos,posmax,posmin,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=chkmin(negmin,i),negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos,posmax=chkmax(posmax,i),posmin=chkmin(posmax,i);
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1,--cnt;
			zer=1,zerx=i;
		}
	}if(cnt<=1)return 0;
	if(zer==1&&(neg&1)){
		cout<<1<<' '<<zerx<<' '<<negmax<<endl,--cnt;used[zerx]=1;
		if(cnt>1)delout(zerx);else delout(0);return 0;
	}else if(zer==1){delout(zerx);return 0;}
	else if(neg&1){delout(negmax);return 0;}
	else delout(0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,negmin,pos,posmax,posmin,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=chkmin(negmin,i),negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos,posmax=chkmax(posmax,i),posmin=chkmin(posmax,i);
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1;
			zer=1,zerx=i;--cnt;
		}
	}
	if(zer==1&&neg&1){
		delout(0);return 0;
	}else if(zer==1&&cnt!=1){delout(zerx);return 0;}
	else if(neg&1){delout(negmin);return 0;}
	else delout(0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,negmin,pos,posmax,posmin,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=chkmin(negmin,i),negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos,posmax=chkmax(posmax,i),posmin=chkmin(posmax,i);
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1,--cnt;
			zer=1,zerx=i;
		}
	}if(cnt<=1)return 0;
	if(zer==1&&(neg&1)){
		cout<<1<<' '<<zerx<<' '<<negmax<<endl;used[zerx]=1;
		delout(0);return 0;
	}else if(zer==1){delout(zerx);return 0;}
	else if(neg&1){delout(negmax);return 0;}
	else delout(0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,negmin,pos,posmax,posmin,zer;
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	cout<<2<<' '<<x<<endl;
	if(x==n){for(int i=1;i<n-1;++i)cout<<1<<' '<<i<<' '<<i+1<<endl;return;}
	else{
		for(int i=1;i<n;++i){
			if(i==x)continue;
			if(i+1==x)cout<<1<<' '<<i<<' '<<i+2<<endl;
			else cout<<1<<' '<<i<<' '<<i+1<<endl;
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=min(negmin,a[i]),negmax=max(negmax,a[i]);
		else if(a[i]>0)++pos,posmax=max(posmax,a[i]),posmin=min(posmax,a[i]);
		else ++zer,zerx=i;
	}
	if(zer>1||(zer==1&&neg&1)){
		for(int i=1;i<n;++i)cout<<1<<' '<<i<<' '<<i+1<<endl;
		return 0;
	}else if(zer==1){delout(zerx);return 0;}
	else if(neg&1){delout(negmin);return 0;}
	else for(int i=1;i<n;++i)cout<<1<<' '<<i<<' '<<i+1<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,negmin,pos,posmax,posmin,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=chkmin(negmin,i),negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos,posmax=chkmax(posmax,i),posmin=chkmin(posmax,i);
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1,--cnt;
			zer=1,zerx=i;
		}
	}if(cnt<=1)return 0;
	if(zer==1&&(neg&1)){
		delout(0);return 0;
	}else if(zer==1){delout(zerx);return 0;}
	else if(neg&1){delout(negmin);return 0;}
	else delout(0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,pos,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=0;a[0]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos;
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1,--cnt;
			zer=1,zerx=i;
		}
	}if(cnt<=1)return 0;
	if(zer==1&&(neg&1)){
		cout<<1<<' '<<zerx<<' '<<negmax<<endl,--cnt;used[zerx]=1;
		if(cnt>1)delout(negmax);else delout(0);return 0;
	}else if(zer==1){delout(zerx);return 0;}
	else if(neg&1){delout(negmax);return 0;}
	else delout(0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,negmin,pos,posmax,posmin,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=chkmin(negmin,i),negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos,posmax=chkmax(posmax,i),posmin=chkmin(posmax,i);
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1;
			zer=1,zerx=i;--cnt;
		}
	}
	if(zer==1&&(neg&1)){
		delout(0);return 0;
	}else if(zer==1&&cnt){delout(zerx);return 0;}
	else if(neg&1){delout(negmin);return 0;}
	else delout(0);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5,INF=0x3f3f3f3f;
int n,a[N];int neg,zerx,negmax,cnt,negmin,pos,posmax,posmin,zer;bool used[N];
inline int chkmax(int x,int y){
	return a[x]>a[y]?x:y;
}
inline int chkmin(int x,int y){
	return a[x]<a[y]?x:y;
}
inline void delout(int x){
	if(x)cout<<2<<' '<<x<<endl,used[x]=1;
	for(int i=1;i<n;){
		if(used[i]){++i;continue;}
		int j=i+1;while(j<=n&&used[j])++j;if(j>n)break;
		cout<<1<<' '<<i<<' '<<j<<endl;
		i=j;
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin>>n;negmax=posmin=0;negmax=posmin=n+2;a[0]=INF;a[n+2]=-INF;cnt=n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		if(a[i]<0)++neg,negmin=chkmin(negmin,i),negmax=chkmax(negmax,i);
		else if(a[i]>0)++pos,posmax=chkmax(posmax,i),posmin=chkmin(posmax,i);
		else {
			if(zer)cout<<1<<' '<<zerx<<' '<<i<<endl,used[zerx]=1;
			zer=1,zerx=i;--cnt;
		}
	}
	if(zer==1&&neg&1){
		delout(0);return 0;
	}else if(zer==1&&cnt==1){delout(zerx);return 0;}
	else if(neg&1){delout(negmin);return 0;}
	else delout(0);
	return 0;
}