#include <bits/stdc++.h> // All praise is due to Allah alone, and peace and blessings be
using namespace std; // upon him, after whom there is no other Prophet.
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
int32_t Case = 1; cin >> Case;
for (int T = 1; T <= Case; T++) {
int n; cin >> n;
int ar[n]; for(int & i : ar) cin >> i;
vector<int> br(ar, ar + n);
sort(br.begin(), br.end());
function<void()> Test_Case = [&]() {
int i = 0, j = n - 1;
auto it = lower_bound(br.begin(), br.end(), ar[i]);
int ind = it - br.begin();
i++;
int l = ind - 1, r = ind + 1;
while(i <= j) {
if(l >= 0 and ar[i] == br[l]) {
i++, l--;
}
else if(r < n and ar[i] == br[r]) {
i++, r++;
}
else if(l >= 0 and ar[j] == br[l]) {
j--, l--;
}
else if(r < n and ar[j] == br[r]) {
j--, r++;
}
else {
break;
}
}
i = 0, j = n - 1;
it = lower_bound(br.begin(), br.end(), ar[j]);
j--;
ind = it - br.begin();
l = ind - 1, r = ind + 1;
while(i <= j) {
if(l >= 0 and ar[i] == br[l]) {
i++, l--;
}
else if(r < n and ar[i] == br[r]) {
i++, r++;
}
else if(l >= 0 and ar[j] == br[l]) {
j--, l--;
}
else if(r < n and ar[j] == br[r]) {
j--, r++;
}
else {
cout << "NO\n"; return;
}
}
cout << "YES\n";
};
Test_Case();
}
return 0;
}