#include <bits/stdc++.h>
using namespace std;
#define optimize() \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);cout.tie(NULL);
#define fraction() \
cout.unsetf(ios::floatfield); \
cout.precision(20); \
cout.setf(ios::fixed, ios::floatfield);
#define file() \
freopen("input.txt", "r", stdin); \
freopen("output", "w", stdout);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pr;
template <typename T> using ordered_set = tree <T, null_type,less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll lcm(ll a, ll b)
{
return (a * b) / __gcd(a, b);
}
int gcd(ll a, ll b)
{
return __gcd(a, b);
}
#define el "\n"
const int mod = 1e9+7;
const int mx = 5e5 + 125;
bool com(const pair<ll, ll> &p1, const pair<ll, ll> &p2)
{
if (p1.first == p2.first) return p1.second > p2.second;
return p1.first < p2.first;
}
bool compare(const pair<pair<int, int>, int>& a, const pair<pair<int, int>, int>& b)
{
if (a.first.first != b.first.first)
return a.first.first < b.first.first;
if (a.first.second != b.first.second)
return a.first.second < b.first.second;
return a.second < b.second;
}
//const int mx = 1e8;
bitset<mx> isPrime;
vector<int> primes;
map<int,int>m;
void primeGen ( int n )
{
for ( int i = 3; i <= n; i += 2 ) isPrime[i] = 1;
int sq = sqrt(n);
for ( int i = 3; i <= sq; i += 2 )
{
if(isPrime[i])
{
for ( int j = i*i; j <= n; j += i )
{
isPrime[j] = 0;
}
}
}
primes.push_back(2);
for ( int i = 3; i <= n; i += 2 )
{
if(isPrime[i] == 1)
{
primes.push_back(i);
}
}
}
void factors(int x)
{
for ( auto p : primes )
{
for ( int i = p; i <= primes.size(); i += p )
{
int n = x;
while ( n % p == 0 )
{
//factors[i].push_back(p);
m[p]++;
n /= p;
}
}
}
}
int power(ll x,ll y)
{
int num=1;
for(int i=0; i<y; i++)
{
num*=3;
}
return num;
}
void giveanswer()
{
int n,i;
cin>>n;
vector<int>a(n);
deque<int>b;
for(i=0;i<n;i++)
{
cin>>a[i];
b.push_back(a[i]);
}
deque<int>d;
while(b.size())
{
int x=b.front();
int y=b.back();
if(x>=y)
{
if(d.size()==0)
{
d.push_back(x);
b.pop_front();
}
else
{
if(x>=d.back())
{
d.push_back(x);
b.pop_front();
}
else if(x<=d.front())
{
d.push_front(x);
b.pop_front();
}
else
{
cout<<"NO"<<el;
return;
}
}
}
else
{
if(d.size()==0)
{
d.push_back(y);
b.pop_back();
}
else
{
if(y>=d.back())
{
d.push_back(y);
b.pop_back();
}
else if(x<=d.front())
{
d.push_front(y);
b.pop_back();
}
else
{
cout<<"NO"<<el;
return;
}
}
}
}
vector<int>ans;
while(d.size())
{
//cout<<d.front()<<el;
ans.push_back(d.front());
d.pop_front();
}
for(i=0;i<ans.size()-1;i++)
{
if(ans[i+1]<ans[i])
{
cout<<"NO"<<el;
return;
}
}
cout<<"YES"<<el;
}
int main()
{
optimize();
fraction();
int t;
cin>>t;
while(t--)
{
giveanswer();
}
}