Map

No attempts yetTime limit1sMemory limit128 MB

Problem

In Byteland, a new institution has been founded to study how similar the country's various regions are to one another. The map of the country is an n×mn \times m rectangle made up of nmn \cdot m unit squares. Each square is a province, and every province is assigned exactly one natural number describing a characteristic feature (for example, 1 for coal deposits, 2 for lakes, and so on).

Two regions are called kk-similar if, among all pairs of corresponding provinces, at most kk pairs have differing features (all the others are identical). Given the map, you must answer queries asking whether two given regions are kk-similar.

For example, consider the following two 3×33 \times 3 regions:

113
523
628
913
513
628

The two regions above are 2-similar and 3-similar, but they are neither 1-similar nor 0-similar.

Input

The first line contains three integers nn, mm, qq (1n,m2001 \le n, m \le 200, 1q200001 \le q \le 20000): the number of rows and columns of the map and the number of queries. Each of the next nn lines describes the map; line i+1i+1 contains mm integers ai,1,,ai,ma_{i,1}, \dots, a_{i,m} (1ai,j1001 \le a_{i,j} \le 100), where ai,ja_{i,j} is the feature of the province in row ii, column jj (rows and columns are numbered from 1).

Each of the next qq lines contains one query as seven integers x1 y1 x2 y2 w h kx_1\ y_1\ x_2\ y_2\ w\ h\ k (0k10000 \le k \le 1000, 1wm1 \le w \le m, 1hn1 \le h \le n). The two regions are rectangles whose top-left province lies at (column x1x_1, row y1y_1) and (column x2x_2, row y2y_2) respectively, each spanning ww columns across and hh rows down; their bottom-right provinces are therefore at (column x1+w1x_1+w-1, row y1+h1y_1+h-1) and (column x2+w1x_2+w-1, row y2+h1y_2+h-1). Both regions lie entirely inside the map. Decide whether the two regions are kk-similar.

Output

Print qq lines, one per query: TAK if the two regions are kk-similar, or NIE otherwise.