#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <vector>
#include <stack>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int main(void)
{
    int s[10], n, b, c;
    bool flag;

    cin >> n;
    rep(i, n) {
        b = 0, c = 0, flag = true;
        rep(i, 10)
            cin >> s[i];
        rep(i, 10) {
            if (s[i] > b)
                b = s[i];
            else if (s[i] > c)
                c = s[i];
            else
                flag = false;
        }
        
        cout << (flag ? "YES" : "NO") << endl;
    }
    return 0;
}