#include<stdio.h>
#include<stdlib.h>
#pragma warning(disable:4996)
typedef struct node{
int x;
int y;
int val;
}node;
int t, n, w, k;
#define SIZE 100000
#define SIZE1 10000
node point[SIZE + 1];
node point1[SIZE + 1];
int hash[SIZE1 + 1][SIZE1 + 1];
int hashTable[SIZE + 1];
int getHash(int n)
{
return 1 + n%SIZE1;
}
int bfs()
{
int head = 0;
int wei = 0;
for (int i = 1; i <= n; i++)
{
point[i].val = point[i].val - k;
if (point[i].val <= 0)
{
point1[wei++] = point[i];
}
}
while (head != wei)
{
int nx = getHash(point1[head].x / 10);
int ny = getHash(point1[head].y / 10);
for (int i = nx - 1; i <= nx + 1; i++)
for (int j = ny - 1; j <= ny + 1; j++)
for (int h = hash[i][j]; h > 0; h = hashTable[h])
{
if (point[h].val > 0)
{
int dx = point[h].x - point1[head].x;
int dy = point[h].y - point1[head].y;
if (dx < 0) dx = -dx;
if (dy < 0) dy = -dy;
int dead = 10 / (dx + dy);
point[h].val = point[h].val - dead;
if (point[h].val <= 0)
{
point1[wei++] = point[h];
}
}
}
head++;
}
return n - wei;

}
int main()
{
freopen("input.txt", "r", stdin);
scanf("%d", &t);
for (int t1 = 1; t1 <= t; t1++)
{
scanf("%d%d%d", &n, &w, &k);
for (int i = 1; i <= n; i++)
{
scanf("%d%d%d", &point[i].x, &point[i].y, &point[i].val);
}
for (int i = 1; i <= n; i++)
{
int nx = getHash(point[i].x/10);
int ny = getHash(point[i].y/10);
hashTable[i] = hash[nx][ny];
hash[nx][ny] = i;
}

printf("#%d %d\n", t1, bfs());

for (int i = 1; i <= n; i++)
{
int nx = getHash(point[i].x / 10);
int ny = getHash(point[i].y / 10);
hash[nx][ny] = 0;
}
}

}

 

 

 

 

 

 

 

 

2

4 4 4

2 2 7

4 1 9

4 4 9

1 4 3

4 4 3

2 2 7

4 1 9

4 4 9

1 4 3