#include <cstdio>
#include <iostream>
using namespace std;

#define REP(i, n)       REPEAT(i, 0, n)
#define REPEAT(i, k, n) for (int i = (k); i < (n); ++i)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

int main(){
    int n;
    cin >> n;
    REP(i,n){
        int a, p1 = 0, p2 = 0;
        bool flag = true;
        REP(j,10){
            cin >> a;
            if(p1 < a){
                p1 = a;
            } else if(p2 < a){
                p2 = a;
            } else {
                flag = false;
            }
            pf("DEBUG: %d %d %d\n", a, p1, p2);
        }
        cout << (flag?"YES":"NO") << endl;
    }
    return 0;
}