#include <iostream>

using namespace std;

bool ballTest(int *balls, int *b, int numB, int *c, int numC, int num)
{
        if (num <= 0) {
                return true;
        }
        if (balls[0] > b[numB - 1]) {
                b[numB] = balls[0];
                if (ballTest(&balls[1], b, numB + 1, c, numC, num - 1)) {
                        return true;
                }
        }
        if (balls[0] > c[numC - 1]) {
                c[numC] = balls[0];
                if (ballTest(&balls[1], b, numB, c, numC + 1, num - 1)) {
                        return true;
                }
        }
        return false;
}


int main(int argc, char **argv)
{
        int num;

        cin >> num;

        for (int i = 0; i < num; i++) {
                int balls[11];
                int b[10], c[10];
                int numB, numC;

                b[0] = c[0] = 0;
                numB = numC = 1;
                cin >> balls[1] >> balls[2] >> balls[3] >> balls[4] >> balls[5] >> balls[6] >> balls[7] >> balls[8] >> balls[9] >> balls[10];
                if (ballTest(&balls[1], b, 1, c, 1, 10)) {
                        cout << "YES\n";
                } else {
                        cout << "NO\n";
                }
        }
        return 0;
}