#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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