#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);
}
auto temp = dq;
vector<ll> v;
for (ll i = 1; i <= n; i++) {
ll mn = min(dq.front(), dq.back());
v.push_back(mn);
if (dq.front() == mn) dq.pop_front();
else dq.pop_back();
}
if (is_sorted(v.begin(), v.end()) and v[0] <= v.back()) {
cout << "YES\n";
goto test;
}
dq = temp;
v.clear();
for (ll i = 1; i <= n; i++) {
ll mx = max(dq.front(), dq.back());
v.push_back(mx);
if (dq.front() == mx) dq.pop_front();
else dq.pop_back();
}
reverse(v.begin(), v.end());
if (is_sorted(v.begin(), v.end()) and v[0] <= v.back()) {
cout << "YES\n";
goto test;
}
cout << "NO\n";
}
}