import sys
from collections import deque
def solve():
"""
Solves a single test case for the beautiful array problem.
"""
try:
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split()))
except (IOError, ValueError):
return
# A deque for efficient removal from both ends
a_deque = deque(a)
# A sorted version for reference
a_sorted = sorted(a)
# Pointers for the sorted reference array
left_s = 0
right_s = n - 1
possible = True
while a_deque:
# These are the smallest and largest elements we need to find
target_min = a_sorted[left_s]
target_max = a_sorted[right_s]
# Check the left end of the current array A
if a_deque[0] == target_min:
a_deque.popleft()
left_s += 1
elif a_deque[0] == target_max:
a_deque.popleft()
right_s -= 1
# Check the right end of the current array A
elif a_deque[-1] == target_min:
a_deque.pop()
left_s += 1
elif a_deque[-1] == target_max:
a_deque.pop()
right_s -= 1
# If no match is found, it's impossible
else:
possible = False
break
if possible:
print("YES")
else:
print("NO")
def main():
"""
Main function to handle multiple test cases.
"""
try:
num_test_cases = int(sys.stdin.readline())
for _ in range(num_test_cases):
solve()
except (IOError, ValueError):
pass
if __name__ == "__main__":
main()