//刚开始没看4MS,看了下一般搜索肯定超时,于是全存(Memory)囧。
//然后看了下时间4MS 正规化操作(TIME) T.T
//后来吃饭听同学说数字是1到N有序的,顿悟! 优化了下,2986MS
#include<iostream>
#include<stdlib.h>
using namespace std;
int T,N;
struct Node
{
int value,subscript;
}node[10001];
int i,j,l;
//快排比较函数
int cmp(const void *p,const void *q)
{
int c = (*(struct Node*)p).value - (*(struct Node*)q).value;
if(c>0) return 1;
else return -1;
}
int main()
{
cin>>T;
while(T--)
{
cin>>N;
for(i=1;i<=N;i++)
{
scanf("%d",&node[i].value);
node[i].subscript=i;
}
node[0].value=-1;
qsort(node,N+1,sizeof(struct Node),cmp);//快排
bool IsOk = false;
int begin,min;
for(i=2;i<N;i++)//去掉首尾作为中间的机会
{
begin=i;
min=i-1<=N-i?i-1:N-i;
for(j=1;j<=min;j++)
{
//如果与中心等距离并且满足下标递增,则OK
if(node[begin-j].subscript<node[i].subscript && node[i].subscript<node[begin+j].subscript)
{
IsOk=true;
break;
}
else if(node[begin-j].subscript>node[i].subscript && node[i].subscript>node[begin+j].subscript)
{
IsOk=true;
break;
}
if(IsOk) break;
}
}
if(IsOk) printf("Y\n");
else printf("N\n");
}
return 0;
}