#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    while (n--) {
        int left = 0, right = 0;
        int i;
        for (i = 0; i < 10; i++) {
            int ball;
            cin >> ball;
            if (left > ball && right > ball) {
                cout << "NO" << endl;
                break;
            }
            if (left > ball)
                right = ball;
            else if (right > ball)
                left = ball;
            else if (left > right)
                left = ball;
            else
                right = ball;
        }
        if (i == 10)
            cout << "YES" << endl;
    }
    return 0;
}