Lemurs
Time limit4sMemory limit1024 MB
Given an n by m grid of marked cells, decide whether some set of taxicab balls of radius k, each lying inside the grid, covers exactly the marked cells.
- Level
Medium6 of 10
- Topics
- Prefix sum, Matrix, Greedy
- Solved
- No attempts yet
Statement
Bajtazar has been sent on a mission to the jungle. He is going to study the behavior of a newly discovered species, taxicab lemurs.
Taxicab lemurs are known to live in groups. Each group lives in exactly one cell of the jungle, where and . The jungle is an rectangle. The foraging area of a group is the ball of taxicab radius around its cell: the set of cells with , , and . The constant is the same for all groups.
The last researcher on this expedition has disappeared, leaving behind an map where some cells are marked as foraging area. The circumstances are unclear. The latest theory suggests the newly discovered species may not be herbivorous after all.
Bajtazar wants to know whether the map can be trusted. He asks whether there is a set of groups whose foraging areas match exactly the marked cells.
Input
The first line contains the number of test cases (). Each test case follows.
The first line of each test case contains , , and (), with the meanings given in the statement.
The next lines describe the map. If the map shows lemurs foraging on cell , then the -th character of the -th line is x. Otherwise it is a dot.
The sum of over all test cases does not exceed .
Output
For each test case, print one line. Print TAK if such a set of groups exists, otherwise print NIE.
Hint
In the first test case, the marked foraging area is produced by three groups living in cells , , and .
In the second test case, no set of groups produces the foraging area shown on the map.