#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using dt = array<int, 2>;
void test() {
int n;
cin >> n;
deque<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
auto a = v;
auto c = a;
sort(c.begin(), c.end());
bool ok = true;
for (int i = 0; i < n; i++) {
if (c[i] == v.back()) {
v.pop_back();
} else if (c[i] == v.front()) {
v.pop_front();
} else {
ok = false;
break;
}
}
if (ok) {
cout << "YES\n";
return;
}
v = a;
ok = true;
sort(c.begin(), c.end(), greater<>());
for (int i = 0; i < n; i++) {
if (c[i] == v.back()) {
v.pop_back();
} else if (c[i] == v.front()) {
v.pop_front();
} else {
ok = false;
break;
}
}
if (ok) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
for (int i = 1; i <= T; i++) {
test();
}
return 0;
}