#include <iostream>
#include <fstream>
using namespace std;

int field[105][105];
int rezfield[105][105];
int way[105][105];
int n,m;
void printfield()
{
	int i, j;
	for(i=0;i<n;i++)
	{
		for(j=1;j<=m;j++)
		{
			cout.width(4);
			cout << field[i][j] << ' ';
		}
		cout << endl;
	}	
	cout << endl;
}
int goCrol()
{
	int i,j,rez=0, cmax,imax,limax;
	imax=1;
	for(j=2;j<=m;j++)
		if(field[0][j]>=field[0][imax])
			imax=j;
	rez=field[0][imax];
	field[0][imax]=0;
	limax=imax;
	for(i=1;i<n;i++)
	{
		imax=limax-1;
		for(j=limax;j<=limax+1;j++)
			if(field[i][j]>=field[i][imax])
				imax=j;
		rez+=field[i][imax];
		field[i][imax]=0;
		limax=imax;
	}
	return rez;

}
int goHom()
{
	int i,j,rez=0,k,imax;
	for(j=0;j<=(m+1);j++)
		rezfield[0][j]=field[0][j];
	for(i=1;i<n;i++)
		for(j=1;j<=m;j++)
			{
				imax=j-1;
				for(k=j;k<=j+1;k++)
					if(rezfield[i-1][k]>=rezfield[i-1][imax])
						imax=k;
				rezfield[i][j]=field[i][j]+rezfield[i-1][imax];
				way[i][j]=imax;
			}
	imax=1;
	for(j=2;j<=m;j++)
		if(rezfield[n-1][j]>=rezfield[n-1][imax])
			imax=j;
	rez=rezfield[n-1][imax];
	for(i=n-1;i>=0;i--)
	{
		field[i][imax]=0;
		imax=way[i][imax];
	}
	return rez;
}

int main()
{
	int tests, i, j, sum, crol, hom, ccrol, chom;
	ifstream in("hamsters.in");
	in >> tests;
	while(tests)
	{
		in >> n >> m;
		sum=0;
		crol=0;
		hom=0;
		for(i=0;i<n;i++)
		{
			field[i][0]=-1;
			rezfield[i][0]=-1;
			for(j=1;j<=m;j++)
			{
				in >> field[i][j];
				sum+=field[i][j];
			}
			field[i][m+1]=-1;
			rezfield[i][m+1]=-1;
		}
		//printfield();
		while(sum)
		{
			ccrol=goCrol();
			//printfield();
			chom=goHom();
			//printfield();
			sum-=(ccrol+chom);
			crol+=ccrol;
			hom+=chom;
			//cout << crol << ' ' << hom << endl;
		}
		cout << crol << ' ' << hom << endl;
		tests--;
	}
	return 0;
}
