#include <iostream>
#include <stack>
using namespace std;
int main()
{
    int N; cin >> N;
    while (N--) {
        int a[10];
        stack<int> b, c;
        for (int i = 0; i < 10; ++i) cin >> a[i];
        b.push(0);
        c.push(0);
        bool ok = true;
        for (int i = 0; i < 10; ++i) {
            if (b.top() > c.top()) {
                if (b.top() < a[i]) b.push(a[i]);
                else if (c.top() < a[i]) c.push(a[i]);
                else ok = false;
            }
            else {
                if (c.top() < a[i]) c.push(a[i]);
                else if (b.top() < a[i]) b.push(a[i]);
                else ok = false;
            }
        }
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}