QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 10

#11175. (K,N)-knight [B]

统计

Bytean chess is one of the most peculiar variants of chess in the world. Playing each match is a major difficulty, because the game is played on an infinite chessboard. The basic ability learnt by young enthusiasts of Bytean chess is considering all possible situations on a chessboard after millions of moves. To perform this, they need to know whether a given chess piece can get from one given square to another one.

The most powerful chess piece in Bytean chess is a $(K,N)$-knight. Its moves resemble the moves of a knight in traditional chess. Each of its moves consists of: either moving $K$ squares vertically and afterwards $N$ squares horizontally, or moving $N$ squares vertically and afterwards $K$ squares horizontally. The knight from traditional chess can therefore be thought of as $(2,1)$-knight or $(1,2)$-knight.

The task is to verify, for two given squares of the chessboard, if a $(K,N)$-knight can get from the first square to the second one (the number of necessary moves is not important).

Input Format

The first line of the standard input contains one integer T ($1 ≤ T ≤ 20\,000$) denoting the number of test cases. Each of the following T lines contains a description of a single test case in the form of six integers $K$, $N$, $x_1$, $y_1$, $x_2$, $y_2$ ($0 ≤ K, N ≤ 10^{9}$, $K+N > 0$, $-10^{9} ≤ x_1,y_1,x_2,y_2 ≤ 10^{9}$) separated by single spaces. $K$ and $N$ describe the possible moves of the knight. The knight starts its movement in square $(x_1, y_1)$. W would like to check if it can get to square $(x_2, y_2)$.

Output Format

For each test case exactly one line should be written to the standard output. It should contain a word TAK (meaning YES) or NIE (meaning NO) depending on whether a $(K,N)$-knight starting from square $(x_1,y_1)$ can get to square $(x_2,y_2)$.

Example

Input

3
2 1 0 0 3 3
1 1 1 1 1 2
1 0 2 3 4 6

Output

TAK
NIE
TAK
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.