#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;

int main() 
{
    int n; cin >> n;
    int ball[10];
    for(int i = 0; i < n; i++){
        bool can = true;
        for(int j = 0; j < 10; j++){
            cin >> ball[j];
        }
        int k = ball[0];
        int l = 0;
        for(int j = 1; j < 10; j++){
            if(ball[j]>k){
                k=ball[j];
            }else{
                if(l>ball[j]){
                    can = false;
                    break;
                }else{
                    l = ball[j];
                }
            }
        }
        if(can) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}
