#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
#include <queue>
#include <functional>
const int INF =1e5;
const int MOD = 1e9 + 7;
using namespace std;
typedef pair<int,int> P;
typedef long long lint;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define all(x) (x).begin(),(x).end()
#define pb push_back
vector<int> a;
vector<int> b;
int v[10];
bool dfs(int,int,int);

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;++i){
        rep(i,10) cin>>v[i];
        if(dfs(0,0,0)) cout<<"YES"<<endl;
        else  cout<<"NO"<<endl;
    }
    return 0;
}
bool dfs(int i,int a,int b){
    if(i==10)return true;
    if(a<v[i]) return dfs(i+1,v[i],b);
    if(b<v[i]) return dfs(i+1,a,v[i]);
    if(a>=v[i] && b>=v[i])return false;
    return false;
}

