/**
* author: Binoy Barman
* created: 2025-08-31 09:42:08
**/
#include<bits/stdc++.h>
#ifdef LOCAL
#include "algo/debug.h"
#else
#define dbg(...) 42
#endif
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = 2e9;
#define int long long
#define nl '\n'
#define all(v) v.begin(), v.end()
#define clg(x) (32 - __builtin_clz(x))
#define Testcase_Handler int tts, tc = 0; cin >> tts; hell: while(tc++ < tts)
#define uniq(v) sort(all(v)), v.resize(distance(v.begin(), unique(v.begin(), v.end())))
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> istream& operator>>(istream& in, vector<T>& a) {for(auto &x : a) in >> x; return in;};
template<typename T> ostream& operator<<(ostream& out, vector<T>& a) {bool first = true;for(auto &x : a) {if(!first) out << ' ';first = false;out << x;}return out;};
namespace Dark_Lord_Binoy {
inline void init() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
}
}
int32_t main() {
Dark_Lord_Binoy::init();
Testcase_Handler {
int n;
cin >> n;
vector<int> a(n);
cin >> a;
if(n == 1) {
cout << "YES" << nl;
goto hell;
}
vector<int> c(a);
sort(all(c));
int f_id = -1, l_id = -1;
for (int i = 0; i < n; i++) {
if(c[i] == a[0]) {
f_id = i;
}
if(c[i] == a[n - 1]) {
l_id = i;
}
}
bool ok = true;
int i = 1, j = n - 1; // a - initial
int l = f_id - 1, r = f_id + 1; // c - sorted
while(i <= j) {
if(l >= 0 && a[i] == c[l]) {
i++;
l--;
}
else if(l >= 0 && a[j] == c[l]) {
j--;
l--;
}
else if(r < n && a[i] == c[r]) {
i++;
r++;
}
else if(r < n && a[j] == c[r]) {
j--;
r++;
}
else {
ok = false;
break;
}
}
if(ok) {
cout << "YES" << nl;
goto hell;
}
ok = true;
i = 1, j = n - 1; // a - initial
l = l_id - 1, r = l_id + 1; // c - sorted
while(i <= j) {
if(l >= 0 && a[i] == c[l]) {
i++;
l--;
}
else if(l >= 0 && a[j] == c[l]) {
j--;
l--;
}
else if(r < n && a[i] == c[r]) {
i++;
r++;
}
else if(r < n && a[j] == c[r]) {
j--;
r++;
}
else {
ok = false;
break;
}
}
cout << (ok ? "YES" : "NO") << nl;
}
dbg(_Time_);
return 0;
}