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.

Discussions

About Discussions

The discussion section is only for posting: Editorials, General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues. Submitting multiple issues may cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.