#include <bits/stdc++.h>
using namespace std;
int A[15];
bool dfs(int n, int a, int b)
{
    bool ret = false;
    if(n == 10) return (true);
    if(A[n] > a) ret |= dfs(n + 1, A[n], b);
    if(A[n] > b) ret |= dfs(n + 1, a, A[n]);
    return (ret);
}
int main()
{
    int N;
    cin >> N;
    while(N--) {
        for(int i = 0; i < 10; i++) cin >> A[i];
        if(dfs(0, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return (0);
}