// @rakibul-islam
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const ll oo = 1e17;
const ll mod = 1e9 + 7;
void solve() {
int n; cin >> n;
deque<int> dq(n);
for (int i = 0; i < n; i++) {
cin >> dq[i];
}
deque<int> a;
while(dq.size()) {
int x = -1;
if (dq.back() > dq.front()) {
x = dq.front();
dq.pop_front();
} else {
x = dq.back();
dq.pop_back();
}
if (!a.size()) a.push_back(x);
else {
if (a.back() <= x) a.push_back(x);
else a.push_front(x);
}
}
cout << (is_sorted(a.begin(), a.end()) ? "YES\n" : "NO\n");
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1; cin >> t;
for (int test = 1; test <= t; test++) {
solve();
}
return 0;
}