#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0){
        int b = 0, c = 0;
        bool ok = true;
        for(int i=0; i<10; ++i){
            int a;
            cin >> a;
            if(a > b && a > c){
                if(b > c)
                    b = a;
                else
                    c = a;
            }else if(a > b)
                b = a;
            else if(a > c)
                c = a;
            else
                ok = false;
        }
        if(ok)
            cout << "YES" << endl;
        else
            cout << "NO" << endl;
    }

    return 0;
}