#include <iostream>
using namespace std;

int main()
{
        int n;
        int b = 0;
        int c = 0;
        int d = 0;
        int A[10] = {};
        int B[10] = {};
        int C[10] = {};
        cin >> n;
        for (int i = 0;i < n;i++) {
                for (int j = 0;j < 10;j++) {
                        cin >> A[j];
                }

                for (int j = 0;j < 10;j++) {
                        if (d == 0) {
                                if (j == 0) {
                                        B[0] = A[0];
                                        b++;
                                }
                                if ((A[j] > B[b]) && (B[b] > C[c])) {
                                        B[b] = A[j];
                                        b++;
                                }
                                if (A[j] > C[c]) {
                                        C[c] = A[j];
                                        c++;
                                }
                                if ((A[j] < B[b - 1]) && (A[j] < C[c - 1])) {
                                        cout << "NO" << endl;
                                        d = 1;
                                }
                        }
                }
                if (d == 0) {
                        cout << "YES" << endl;
                }
                d = 0;
        }
        return 0;
}