#include <iostream>
#include <stack>

int main()
{
    int n;
    std::cin >> n;

    for (int i = 0; i < n; ++i) {
        int a[10];
        for (int j = 0; j < 10; ++j) std::cin >> a[j];

        std::stack<int> s1, s2;
        for (int j = 0; j < 10; ++j) {
            if (s1.empty()) s1.push(a[j]);
            else if (s1.top() < a[j]) s1.push(a[j]);
            else if (s2.empty()) s2.push(a[j]);
            else if (s2.top() < a[j]) s2.push(a[j]);
        }

        if (s1.size() + s2.size() == 10) std::cout << "YES" << std::endl;
        else std::cout << "NO" << std::endl;
    }
}