#include <iostream>
using namespace std;

bool hoge(int a[], int i, int left, int right)
{
    if (i==10)
        return true;
    if (left < a[i])
        if (hoge(a, i+1, a[i], right))
            return true;
    if (right < a[i])
        if (hoge(a, i+1, left, a[i]))
            return true;
    return false;
}

int main(void) {
    int n, a[10];
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 10; ++j)
            cin >> a[j];
        cout << ((hoge(a, 0, 0, 0))? "YES" : "NO") << endl;
    }
    return 0;
}

