#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
#define endl "\n"
#define vi vector<int>
#define mii map<int,int>
#define mci map<char,int>
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
void solve(){
int n; cin >> n;
int ar[n+10], ar2[n+10];
for(int i = 0; i < n; i++){
cin >> ar[i];
ar2[i] = ar[i];
//mp[ar[i]]++;
}
sort(ar2, ar2+n);
int i = 0, j = n-1, k = 0;
bool b1 = true, b2 = true;
for(int m = 0; m < n; m++){
if(ar[i] == ar2[k]){
i++;
k++;
}
else if(ar[j] == ar2[k]){
j--;
k++;
}
//else if(ar[])
else{
b1 = false;
break;
}
}
if(b1 == true ) {
yes
return;
}
int ar3[n+10];
int lk = n-1;
i = 0, j = n-1, k = 0;
for(int l = 0; l < n; l++){
ar3[l] = ar2[lk];
lk--;
}
for(int m = 0; m < n; m++){
if(ar[i] == ar3[k]){
i++;
k++;
}
else if(ar[j] == ar3[k]){
j--;
k++;
}
//else if(ar[])
else{
no
return;
}
}
yes
}
int main()
{
optimize();
int t;
cin >> t;
while(t--) solve();
return 0;
}