#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cassert>

using namespace std;

int N, M, R, H;
vector<vector<int> > X(100, vector<int>(100, 0));

int rabits_move()
{
	int res = 0;

	for (int i = 0, k;i < N;i++)
	{
		if (i == 0)
		{
			k = 0;
			for (int j = 1;j < M;j++)
				if (X[0][j] >= X[0][k])
					k = j;
		}
		else
		{
			int kmax = -1;
			for (int s = -1;s <= 1;s++)
			{
				if (k + s < 0 || k + s >= M)
					continue;
				if (kmax == -1 || X[i][k + s] >= X[i][kmax])
					kmax = k + s;
			}
			k = kmax;
		}

		res += X[i][k];
		X[i][k] = 0;
	}
	return res;
}

int hamsters_move()
{
	int res = 0;

	// DP table.
	//	D[i][j] - number of carrots the hamsters can get
	// if they start at (i, j)
	vector<vector<int> > D(N, vector<int>(M, 0));
	for (int j = 0;j < M;j++)
		D[N-1][j] = X[N-1][j];

	// Path table.
	// (i, j) -> (i+1, P[i][j])
	vector<vector<int> > P(N, vector<int>(M, -1));

	if (N > 1)
		for (int i = N-2;i >= 0;i--)
			for (int j = 0;j < M;j++)
				for (int s = -1;s <= 1;s++)
				{
					if (j + s < 0 || j + s >= M)
						continue;

					if (D[i+1][j+s] + X[i][j] >= D[i][j])
					{
						D[i][j] = D[i+1][j+s] + X[i][j];
						P[i][j] = j + s;
					}
				}

	int jmax = 0;
	for (int j = 1;j < M;j++)
		if (D[0][j] >= D[0][jmax])
			jmax = j;

	res = D[0][jmax];

	// remove carrots on the path
	for (int i = 0;i < N;i++)
	{
		X[i][jmax] = 0;
		jmax = P[i][jmax];
	}

	return res;
}

void solve()
{
	int LR, LH;
	
	while (1)
	{
		LR = rabits_move();
		LH = hamsters_move();

		R += LR;
		H += LH;

		if (LR + LH == 0)
			break;
	}
}

int main()
{
	ifstream in("hamsters.in");

	int tc;
	in >>tc;
	while (tc--)
	{
		in >>N >>M;
		for (int i = 0;i < N;i++)
			for (int j = 0;j < M;j++)
			{
				in >>X[i][j];
				assert(X[i][j] >= 0 && X[i][j] <= 10);
			}
		R = H = 0;
		solve();
		cout <<R <<" " <<H <<endl;
	}

	return 0;
}