#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int nn = 1e5 + 17, mod = 1e9 + 7;
int n, A[nn];
bool pos(bool mxx) {
int i = 1, j = n;
deque<int>V;
if (mxx) {
V.push_back(A[1]);
i++;
}
else {
V.push_back(A[n]);
j--;
}
while(i <= j) {
int mx = V.back();
int mn = V.front();
if (A[i] >= A[j]) {
if (A[j] >= mx) {
V.push_back(A[j]);
j--;
}
else if (A[i] >= mx) {
V.push_back(A[i]);
i++;
}
else {
V.push_front(A[i]);
i++;
}
}
else {
if (A[i] >= mx) {
V.push_back(A[i]);
i++;
}
else if (A[j] >= mx) {
V.push_back(A[j]);
j--;
}
else {
V.push_front(A[j]);
j--;
}
}
}
bool s = true;
for (int i = 1; i < V.size(); i++) {
if (V[i] < V[i - 1]) return false;
}
return true;
}
void Try() {
cin >> n;
//n = 5;
for (int i = 1; i <= n; i++) {
cin >> A[i];
//A[i] = 5;
}
if (pos(1) || pos(0)) cout << "YES\n";
else cout << "NO\n";
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
Try();
}
}