1334. Lollobrigida

单点时限: 2.0 sec

内存限制: 256 MB

A testing track in the factory of hovercrafts is built of standard blocks of different heights. In a perfectly built track, called lollobrigida, there are neither two neighbouring blocks of equal height nor three consecutive blocks with either increasing or decreasing heights.

To express it more formally, let h1,…,hn denote the sequence of heights of blocks belonging to a track. If for each 1 <= i <= n-2 the following conditions are satisfied:

hi < hi+1 and hi+1 > hi+2 or

hi > hi+1 and hi+1 < hi+2,

then we can call such a track lollobrigida.

Example

One cannot build a lollobrigida with the set of blocks of heights: 3, 3, 3, 5, 2 , because two blocks of height 3 would have to stand side by side or one of the following sequences would have to appear in it : (2, 3, 5) or (5,3,2), and these are not allowed.

Here is an example of a lollobrigida built with another set of blocks - (3, 2, 5, 2, 3, 1). One can build also other lollobrigidas with this set.

Task

Write a program which reads the number of sets of data from the text file LOL.IN and for each set:

1.reads the number of blocks and the height of each block,

2.checks if one can build a lollobrigida with this set,

3.writes the answer.

输入格式

In the first line there is one integer d, 1 <= d <= 100, equal to the number of sets of data. In the next line of the file LOL.IN the first set of data begins.

In the first line of each set of data there is one integer n, 3 <= n <= 1000000, which is equal to the number of blocks in this set.

In the following n lines there are heights of blocks. Each line contains one integer h equal to the height of the corresponding block, 1 <= h <= 109.

Next sets of data follow one after another.

输出格式

The out should contain exactly d lines, one for each set of data. One word should be written in the i-th line of the file LOL.OUT:

TAK (which means YES in Polish), if one can build a lollobrigida, with the i-th set

NIE (which means NO in Polish), in the other case.

样例

Input
2
5
3
3
3
5
2
6
3
3
1
5
2
2
Output
NIE
TAK

1 人解决,1 人已尝试。

2 份提交通过,共有 2 份提交。

8.9 EMB 奖励。

创建: 17 年,3 月前.

修改: 7 年,2 月前.

最后提交: 3 年,12 月前.

来源: POI 2000 III Stage

题目标签