QOJ.ac

QOJ

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

#10382. Pedestrian Crossing [B]

统计

Bytie and his friends are going to pass through the main street of Byteburg. The pedestrian crossing consists of alternate white and black stripes painted on the road surface. Bytie brags that he can pass through the street without stepping on any of the white stripes.

Bytie's shoe length is $ s $ and his step length is $ k $. The boy can start his walk at an arbitrary point of the pavement on one side of the crossing. Afterwards he should walk in equal steps along the crossing (that is, orthogonally to the street) without stepping (or even partially stepping) on any white stripe. The front or the back of Bytie's shoe can, however, be "tangent" to some white stripe. After his last step Bytie has to stand with both feet on the pavement on the other side of the crossing. The boy can step on a single black stripe more than once, he can also not step on some black stripe at all.

Unfortunately, Bytie's task turned out to be more complex than he expected because, strangely enough, the stripes were not painted on the crossing evenly... Help Bytie check if he can pass through the street as he declared.

Input Format

The first line of the standard input contains one integer $ t $ ($1 \le t \le 10$) that denotes the number of test cases. $ 2t $ lines follow with descriptions of the respective test cases. The first line of each description contains three integers $ s $, $ k $ and $ n $ ($1 \le s < k ≤ 10^{9}$, $2 \le n \le 500\,000$) that represent Bytie's shoe length, Bytie's step length and the number of stripes in the pedestrian crossing. The second line contains $ n $ integers $ p_{i} $ ($1 \le p_{i} \le 10^{9}$) that represent the lengths of the respective stripes in the crossing: the first stripe is white, the second is black, the third is white and so on.

Output Format

Your program should output $ i $ lines to the standard output. The $ i $-th line should contain a single word TAK or NIE (yes or no in Polish) depending on whether Bytie can pass through the street in the $ i $-th test case according to the aforementioned rules or not.

Example

Input

2
2 8 7
2 5 6 3 2 1 2
2 8 4
1 6 7 4

Output

TAK
NIE
problem_10382_1.gif

The figure shows how Bytie should pass through the street in the first test case.

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.