#include <cstdio>
#include <cstring>
#include <stack>
using namespace std;
int arr[10];
bool visited[10];

int main() {
    int n;
    scanf("%d", &n);
    for (int t = 0; t < n; t++) {
        for (int i = 0; i < 10; i++) scanf("%d", &arr[i]);
        memset(visited, 0, sizeof(visited));
        stack<int>st;
        st.push(arr[0]); visited[0] = true;
        for (int i = 1; i < 10; i++) {
            if (arr[i] > st.top()) { st.push(arr[i]); visited[i] = true; }
        }
        if (st.size() >= 9) printf("YES\n");
        else {
            int minv, mini;
            for (int i = 0; i < 10; i++) if (!visited[i]) { minv = arr[i], mini = i; break; }
            bool flag = true;
            for (int i = mini+1; i < 10; i++) {
                if (!visited[i] && arr[i] > minv) { minv = arr[i]; }
                else if (!visited[i] && arr[i] < minv) { flag = false; break; }
            }
            (flag) ? printf("YES\n") : printf("NO\n");
        }
    }
    return 0;
}

