#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, multiset<int> St) {
for (int i = 1, j = n; i <= j; ) {
int mn = *St.begin();
int mx = *St.rbegin();
if (mxx && A[i] == mx || !mxx && A[i] == mn) {
St.erase(St.find(A[i]));
i++;
continue;
}
if (mxx && A[j] == mx || !mxx && A[j] == mn) {
St.erase(St.find(A[j]));
j--;
continue;
}
return false;
}
return true;
}
void Try() {
cin >> n;
multiset<int>St;
for (int i = 1; i <= n; i++) {
cin >> A[i];
St.insert(A[i]);
}
if (pos(1, St) || pos(0, St)) 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();
}
}