#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int tc; cin >> tc;
test:
while (tc--) {
ll n; cin >> n;
deque<ll> dq;
for (ll i = 1; i <= n; i++) {
ll a; cin >> a;
dq.push_back(a);
}
deque<ll> temp;
for (ll i = 1; i <= n; i++) {
ll mn = min(dq.front(), dq.back());
if (temp.empty()) temp.push_back(mn);
else {
if (temp.front() >= mn) temp.push_front(mn);
else temp.push_back(mn);
}
if (dq.front() == mn) dq.pop_front();
else dq.pop_back();
}
vector<ll> v;
for (auto &u : temp) v.push_back(u);
if (is_sorted(v.begin(), v.end()) and v[0] <= v.back()) cout << "YES\n";
else cout << "NO\n";
}
}