#include <stdio.h>
int map[9][9];
int n, m;
const int dx[8] = { -1,-1,-1,0,1,1, 1, 0 };//왼쪽 위부터 시계방향
const int dy[8] = { -1, 0, 1,1,1,0,-1,-1 };
int main(void)
{
int T;
setbuf(stdout, NULL);
scanf("%d\n", &T);
for (int test_cast = 1; test_cast <= T; test_cast++)
{
scanf("%d%d", &n,&m);
//맵 초기화
for (int i = 0; i < 9; i++)
for (int j = 0; j < 9; j++)
map[i][j] = 0;
int black = 0;
int white = 0;
//1 = 흑 2 = 백
map[n / 2][n / 2] = 2;
map[(n / 2) + 1][(n / 2) + 1] = 2;
map[n / 2][(n / 2)+1] = 1;
map[(n / 2) + 1][(n / 2)] = 1;
int x, y, d;
while (m--)
{
scanf("%d%d%d", &x, &y, &d);
for (int i = 0; i < 8; i++) {//8방향 탐색
int check = 0;
int nextx = x ;
int nexty = y ;
for (int j = 1; j < 9; j++)//가장 많이 탐색해야 하는경우 = 7. 그전에 돌을 바꾸거나 break로 빠져나오게된다.
{
if (nextx + dx[i] * j <= 0 || nexty + dy[i] * j <= 0 || nextx + dx[i] * j > n || nexty + dy[i] * j > n)
{//map 범위를 벗어나면 오류
break;
}
if (map[nextx + dx[i] * j][nexty + dy[i] * j] == 0)
{
check = 0;
break;
}
else if (map[nextx + dx[i] * j][nexty + dy[i] * j] != d)//처음 내꺼를 만나는 위치
{//다른 돌이 있음
check++;
}
else if (map[nextx + dx[i]*j][nexty + dy[i]*j] == d && check!=0)//처음 내꺼를 만나는 위치
{
for (int k = 0; k < check+1; k++)
{
map[nextx + dx[i] * k][nexty + dy[i] * k] = d;
}
check = 0;
break;
}
else//범위를 벗어남
{
break;
}
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (map[i][j] == 1)
black++;
else if (map[i][j] == 2)
white++;
}
}
printf("#%d %d %d\n", test_cast, black, white);
}
}