Time limit
2s
Memory limit
128 MB
Suppose a sequence A[1], A[2], ..., A[n] is encrypted. A certain encryption algorithm has a weakness: for some sequence shapes, the original sequence cannot be recovered uniquely.
Given a sequence, determine whether it has this weakness.
Choose four distinct indices p, q, r, s such that 1 <= p < q < r < s <= n. The sequence has the weakness if at least one of the following conditions holds.
A[q] < A[s] < A[p] < A[r]A[q] > A[s] > A[p] > A[r]The first line contains the number of data sets T, where 1 <= T <= 10.
Each data set consists of two lines. The first line contains the sequence length n, where 4 <= n <= 5,000. The second line contains A[1], A[2], ..., A[n] in order.
Each A[i] is between 1 and 10,000, inclusive, and all values in one data set are distinct.
For each data set, print one line. Print Yes if the sequence has the weakness, and No otherwise.