Under construction

Still being built. Things may change

Lemurs

Time limit4sMemory limit1024 MB

Summary
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 (x,y)(x, y) of the jungle, where 1≤x≤n1 \leq x \leq n and 1≤y≤m1 \leq y \leq m. The jungle is an n×mn \times m rectangle. The foraging area of a group is the ball of taxicab radius kk around its cell: the set of cells (x′,y′)(x', y') with ∣x−x′∣+∣y−y′∣≤k|x - x'| + |y - y'| \leq k, 1≤x′≤n1 \leq x' \leq n, and 1≤y′≤m1 \leq y' \leq m. The constant kk is the same for all groups.

The last researcher on this expedition has disappeared, leaving behind an n×mn \times m 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 zz (1≤z≤4 0001 \leq z \leq 4\,000). Each test case follows.

The first line of each test case contains nn, mm, and kk (1≤n,m,k≤1 0001 \leq n, m, k \leq 1\,000), with the meanings given in the statement.

The next nn lines describe the map. If the map shows lemurs foraging on cell (j,i)(j, i), then the jj-th character of the ii-th line is x. Otherwise it is a dot.

The sum of n+m+kn + m + k over all test cases does not exceed 100 000100\,000.

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 (1,3)(1, 3), (2,2)(2, 2), and (3,1)(3, 1).

In the second test case, no set of groups produces the foraging area shown on the map.

Examples1

  1. Example 1

    Input
    2
    3 3 1
    .xx
    xxx
    xx.
    3 4 1
    ..xx
    x.xx
    x..x
    
    Expected output
    TAK
    NIE