Peaks

Time limit2sMemory limit256 MB

Problem

Sang-geun works at a company that makes large maps. His current task is to find the peaks of mountains in a landscape.

You are given a grid map where each cell has a height. Consider a cell whose height is $h$. Starting from this cell, you may move between orthogonally adjacent cells (up, down, left, right), but you are never allowed to step onto a cell whose height is $h-d$ or lower. If, under this restriction, it is impossible to reach any cell taller than $h$, then the cell is called a $d$-peak. In other words, a cell is a $d$-peak if, using only cells with height greater than $h-d$, you cannot walk to any cell higher than itself.

For example, a cell that is only slightly lower than a summit is not a peak if it connects directly to a higher summit without ever descending to low ground. Conversely, if reaching any higher cell forces you to pass through some sufficiently low cell (height $h-d$ or lower), then the cell is a $d$-peak.

Given the height of every cell, write a program that counts how many cells are $d$-peaks.

Input

The first line contains the number of test cases $T$ ($1 \le T \le 100$).

The first line of each test case contains the map's number of rows $n$, number of columns $m$, and an integer $d$ ($1 \le n, m \le 500$, $1 \le d \le 10^9$). Each of the next $n$ lines contains $m$ integers, the heights $h$ of the cells ($0 \le h \le 10^9$).

Output

For each test case, print the number of $d$-peaks on its own line.