#include <cstdio>
using namespace std;
int n, arr[15];
bool flag;
void dfs(int x1, int x2, int y1, int y2, int cnt)
{
    if (x2 < x1 || y2 < y1)
        return;
    if (cnt == 10)
    {
        flag = true;
        return;
    }
    dfs(x2, arr[cnt], y1, y2, cnt + 1);
    dfs(x1, x2, y2, arr[cnt], cnt + 1);
}
int main()
{
    scanf("%d", &n);
    while (n--)
    {
        for (int i = 0; i < 10; i++)
            scanf("%d", &arr[i]);
        flag = false;
        dfs(0, 0, 0, 0, 0);
        if (flag)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
