Tokens
시간 제한5초메모리 제한512 MB
토큰이 좌표가 커지는 방향으로만 이동할 수 있는 A x B x C 격자에서 초기 상태를 목표 상태로 바꿀 수 있는지 판정한다.
문제
We are given a three-dimensional, long and thin board consisting of unit cubes arranged into an cuboid. Every cell can be described by a triple of integers , where , and . For every cell we know how many tokens are there initially --- in cell there are of them. In one move we can take one cell that has at least one token and move this token to one of cells , or , provided that such cell exists.
Moreover, for every cell we are given a number . Your task is to determine whether it is possible to perform some number of moves (possibly zero), so that for every cell number of tokens that end up there is exactly .
입력
First line contains an integer (), denoting the number of testcases.
Then descriptions of testcases follow. Each of them starts with a line containing three integers , , (, ), denoting dimensions of the board. Then there are blocks of rows. Each of these rows contains numbers --- -th number in -th row of -th block is (). Then, in analogous format, numbers are given ().
Every testcase contains blocks in total. Every two consecutive blocks are separated by an empty line for the sake of readability. Within every testcase, the sum of values is equal to the sum of values .
Sum of values of over all testcases will not exceed .
출력
Output should contain exactly lines, one per each testcase. -th line should contain a word TAK if in -th testcase it is possible to find a required sequence of moves from the initial to the final state, or a word NIE otherwise.
힌트
Explanation to second sample test: Below we present sequence of moves leading from the initial to the final state:
2 2 2 2 2 1 2 1 1 1 1 1 1 1
2 1 2 0 2 1 1 1 2 1 1 2 1 2
-> -> -> -> -> ->
2 1 2 1 2 1 2 1 2 1 2 1 1 2
1 1 1 2 1 2 2 2 2 2 2 2 2 2