아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Tokens

시간 제한5초메모리 제한512 MB

요약
토큰이 좌표가 커지는 방향으로만 이동할 수 있는 A x B x C 격자에서 초기 상태를 목표 상태로 바꿀 수 있는지 판정한다.
난이도

보통10점 중 6점

유형
그리디, 시뮬레이션, 구현, 배열
정답자
아직 제출이 없습니다

문제

We are given a three-dimensional, long and thin board consisting of unit cubes arranged into an A×B×CA \times B \times C cuboid. Every cell can be described by a triple of integers (i,j,k)(i, j, k), where 1≤i≤A1 \leq i \leq A, 1≤j≤B1 \leq j \leq B and 1≤k≤C1 \leq k \leq C. For every cell we know how many tokens are there initially --- in cell (i,j,k)(i, j, k) there are a_i,j,ka\_{i, j, k} of them. In one move we can take one cell that has at least one token and move this token to one of cells (i+1,j,k)(i+1, j, k), (i,j+1,k)(i, j+1, k) or (i,j,k+1)(i, j, k+1), provided that such cell exists.

Moreover, for every cell we are given a number b_i,j,kb\_{i, j, k}. Your task is to determine whether it is possible to perform some number of moves (possibly zero), so that for every cell (i,j,k)(i, j, k) number of tokens that end up there is exactly b_i,j,kb\_{i, j, k}.

입력

First line contains an integer tt (1≤t≤10,0001 \leq t \leq 10\\,000), denoting the number of testcases. 

Then descriptions of tt testcases follow. Each of them starts with a line containing three integers AA, BB, CC (1≤A≤10,0001 \leq A \leq 10\\,000, 1≤B,C≤61 \leq B, C \leq 6), denoting dimensions of the board. Then there are AA blocks of BB rows. Each of these rows contains CC numbers --- kk-th number in jj-th row of ii-th block is a_i,j,ka\_{i, j, k} (0≤a_i,j,k≤10120 \leq a\_{i, j, k} \leq 10^{12} ). Then, in analogous format, numbers b_i,j,kb\_{i, j, k} are given (0≤b_i,j,k≤10120 \leq b\_{i, j, k} \leq 10^{12}).

Every testcase contains 2A2A 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 a_i,j,ka\_{i, j, k} is equal to the sum of values b_i,j,kb\_{i, j, k}.

Sum of values of AA over all testcases will not exceed 10,00010\\,000.

출력

Output should contain exactly tt lines, one per each testcase. kk-th line should contain a word TAK if in kk-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

예제1

  1. 예제 1

    입력
    2
    2 3 4
    2 0 0 1
    0 0 1 0
    1 0 0 0
    
    0 1 0 0
    1 0 0 0
    0 0 0 0
    
    0 0 1 0
    0 1 0 0
    0 0 0 0
    
    1 0 0 0
    0 0 0 0
    0 0 0 4
    2 2 2
    2 2
    2 1
    
    2 1
    1 1
    
    1 1
    1 2
    
    1 2
    2 2
    
    예상 출력
    NIE
    TAK