#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(void) {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    int a[100];
    int i;
    for (i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
    }
    int c = 0;
    for (i = 0; i < n; ++i) {
      int j;
      for (j = i + 2; j < n; ++j) {
        if (a[i] > a[j]) {
          c = 1;
          break;
        }
      }
    }
    if (c == 0)
      printf("YES\n");
    else
      printf("NO\n");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1b0,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec7(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <scanf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
je     1287 <main+0x167>
lea    0xea3(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1040 <scanf@plt>
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11b4 <main+0x94>
movslq -0x1a4(%rbp),%rax
lea    -0x1a0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe65(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    1170 <main+0x50>
movl   $0x0,-0x1a8(%rbp)
movl   $0x0,-0x1a4(%rbp)
mov    -0x1a4(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1258 <main+0x138>
mov    -0x1a4(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x1ac(%rbp)
mov    -0x1ac(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    123f <main+0x11f>
movslq -0x1a4(%rbp),%rax
mov    -0x1a0(%rbp,%rax,4),%eax
movslq -0x1ac(%rbp),%rcx
cmp    -0x1a0(%rbp,%rcx,4),%eax
jle    1226 <main+0x106>
movl   $0x1,-0x1a8(%rbp)
jmp    123f <main+0x11f>
jmp    122b <main+0x10b>
mov    -0x1ac(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1ac(%rbp)
jmp    11e6 <main+0xc6>
jmp    1244 <main+0x124>
mov    -0x1a4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1a4(%rbp)
jmp    11c8 <main+0xa8>
cmpl   $0x0,-0x1a8(%rbp)
jne    1276 <main+0x156>
lea    0xd97(%rip),%rdi
call   1030 <printf@plt>
jmp    1282 <main+0x162>
lea    0xd8b(%rip),%rdi
call   1030 <printf@plt>
jmp    1142 <main+0x22>
xor    %eax,%eax
add    $0x1b0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
lea    0xec8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1040 <scanf@plt>
subl   $0x1,0xc(%rsp)
jae    115d <main+0x3d>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe9c(%rip),%r15
lea    0x8(%rsp),%r14
lea    0xe96(%rip),%r12
lea    0x10(%rsp),%r13
jmp    1199 <main+0x79>
nopw   0x0(%rax,%rax,1)
test   %edi,%edi
lea    0xe7a(%rip),%rdi
cmove  %r12,%rdi
call   1030 <puts@plt>
subl   $0x1,0xc(%rsp)
jb     1149 <main+0x29>
mov    %r15,%rdi
mov    %r14,%rsi
call   1040 <scanf@plt>
cmpl   $0x0,0x8(%rsp)
mov    %r12,%rdi
jle    118d <main+0x6d>
mov    %r13,%rbx
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
call   1040 <scanf@plt>
add    $0x1,%rbp
movslq 0x8(%rsp),%rax
add    $0x4,%rbx
cmp    %rax,%rbp
jl     11c0 <main+0xa0>
mov    %eax,%eax
mov    %r12,%rdi
test   %eax,%eax
jle    118d <main+0x6d>
xor    %ecx,%ecx
mov    %rax,%rdx
mov    %r13,%rsi
xor    %edi,%edi
jmp    121a <main+0xfa>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%edi
add    $0x1,%rcx
add    $0x4,%rsi
add    $0xffffffffffffffff,%rdx
cmp    %rax,%rcx
je     1180 <main+0x60>
lea    0x2(%rcx),%ebp
cmp    %eax,%ebp
jge    1205 <main+0xe5>
mov    0x10(%rsp,%rcx,4),%ebp
mov    $0x2,%ebx
nopw   0x0(%rax,%rax,1)
cmp    (%rsi,%rbx,4),%ebp
jg     1200 <main+0xe0>
add    $0x1,%rbx
cmp    %ebx,%edx
jne    1230 <main+0x110>
jmp    1205 <main+0xe5>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [5 x i8] c"YES\0A\00"
@.str.2 = [4 x i8] c"NO\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [100 x i32]
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
br label %9
9: ; preds = %65, %0
%10 = load i32, i32* %2
%11 = add nsw i32 %10, -1
store i32 %11, i32* %2
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %66
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
store i32 0, i32* %5
br label %15
15: ; preds = %24, %13
%16 = load i32, i32* %5
%17 = load i32, i32* %3
%18 = icmp slt i32 %16, %17
br i1 %18, label %19, label %27
19: ; preds = %15
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %19
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %15
27: ; preds = %15
store i32 0, i32* %6
store i32 0, i32* %5
br label %28
28: ; preds = %55, %27
%29 = load i32, i32* %5
%30 = load i32, i32* %3
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %58
32: ; preds = %28
%33 = load i32, i32* %5
%34 = add nsw i32 %33, 2
store i32 %34, i32* %7
br label %35
35: ; preds = %51, %32
%36 = load i32, i32* %7
%37 = load i32, i32* %3
%38 = icmp slt i32 %36, %37
br i1 %38, label %39, label %54
39: ; preds = %35
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %41
%43 = load i32, i32* %42
%44 = load i32, i32* %7
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds [100 x i32], [100 x i32]* %4, i64 0, i64 %45
%47 = load i32, i32* %46
%48 = icmp sgt i32 %43, %47
br i1 %48, label %49, label %50
49: ; preds = %39
store i32 1, i32* %6
br label %54
50: ; preds = %39
br label %51
51: ; preds = %50
%52 = load i32, i32* %7
%53 = add nsw i32 %52, 1
store i32 %53, i32* %7
br label %35
54: ; preds = %49, %35
br label %55
55: ; preds = %54
%56 = load i32, i32* %5
%57 = add nsw i32 %56, 1
store i32 %57, i32* %5
br label %28
58: ; preds = %28
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %58
%62 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %65
63: ; preds = %58
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
br label %65
65: ; preds = %63, %61
br label %9
66: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@str = [3 x i8] c"NO\00"
@str.3 = [4 x i8] c"YES\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = bitcast i32* %1 to i8*
%5 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%6 = load i32, i32* %1
%7 = add nsw i32 %6, -1
store i32 %7, i32* %1
%8 = icmp eq i32 %6, 0
br i1 %8, label %61, label %9
9: ; preds = %0
%10 = bitcast i32* %2 to i8*
%11 = bitcast [100 x i32]* %3 to i8*
br label %12
12: ; preds = %9, %55
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
%15 = icmp sgt i32 %14, 0
br i1 %15, label %20, label %55
16: ; preds = %20
%17 = icmp sgt i32 %25, 0
br i1 %17, label %18, label %55
18: ; preds = %16
%19 = zext i32 %25 to i64
br label %28
20: ; preds = %12, %20
%21 = phi i64 [ %24, %20 ], [ 0, %12 ]
%22 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %21
%23 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %22)
%24 = add nuw nsw i64 %21, 1
%25 = load i32, i32* %2
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %20, label %16
28: ; preds = %18, %47
%29 = phi i64 [ 0, %18 ], [ %49, %47 ]
%30 = phi i64 [ 2, %18 ], [ %50, %47 ]
%31 = phi i32 [ 0, %18 ], [ %48, %47 ]
%32 = trunc i64 %29 to i32
%33 = add i32 %32, 2
%34 = icmp slt i32 %33, %25
br i1 %34, label %35, label %47
35: ; preds = %28
%36 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %29
%37 = load i32, i32* %36
br label %41
38: ; preds = %41
%39 = trunc i64 %46 to i32
%40 = icmp eq i32 %25, %39
br i1 %40, label %47, label %41
41: ; preds = %35, %38
%42 = phi i64 [ %30, %35 ], [ %46, %38 ]
%43 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp sgt i32 %37, %44
%46 = add nuw nsw i64 %42, 1
br i1 %45, label %47, label %38
47: ; preds = %38, %41, %28
%48 = phi i32 [ %31, %28 ], [ 1, %41 ], [ %31, %38 ]
%49 = add nuw nsw i64 %29, 1
%50 = add nuw nsw i64 %30, 1
%51 = icmp eq i64 %49, %19
br i1 %51, label %52, label %28
52: ; preds = %47
%53 = icmp eq i32 %48, 0
%54 = select i1 %53, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0)
br label %55
55: ; preds = %52, %16, %12
%56 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.3, i64 0, i64 0), %12 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @str.3, i64 0, i64 0), %16 ], [ %54, %52 ]
%57 = call i32 @puts(i8* dereferenceable(1) %56)
%58 = load i32, i32* %1
%59 = add nsw i32 %58, -1
store i32 %59, i32* %1
%60 = icmp eq i32 %58, 0
br i1 %60, label %61, label %12
61: ; preds = %55, %0
ret i32 0
}