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

int main()
{
    int Atop=0, Btop=0, n, ball;
    cin >> n;
    while (n-->0) {
        bool fine = true;
        for (int i = 0; i < 10; ++i) {
            cin >> ball;
            if (ball > max(Atop, Btop)) {
                if (Atop > Btop) Atop = ball;
                else Btop = ball;
            } else if (Atop < ball) {
                Atop = ball;
            } else if (Btop < ball) {
                Btop = ball;
            } else {
                fine = false;
                break;
            }
        }
        cout << (const char *)(fine ? "YES" : "NO") << endl;
    }
}