#include <iostream>
using namespace std;
int main()
{
    int a[20],b[20],c[20];
    int n;
    cin >> n;
    while (n--)
    {
        bool judge = true;
        for (int i = 1; i <= 10; ++i)
            cin >> a[i];
        int cb = 1,cc = 1;
        b[cb++] = a[1],c[cc++] = a[2];
        for (int i = 3; i <= 10; ++i)
        {
            int cha1 = a[i] - b[cb-1];
            int cha2 = a[i] - c[cc-1];
            if (cha1 < 0 && cha2 < 0)
            {
                judge = false;
                break;
            }
            if (cha1 < 0)
                c[cc++] = a[i];
            if (cha2 < 0)
                b[cb++] = a[i];
            if (cha1 < cha2)
                b[cb++] = a[i];
            else c[cc++] = a[i];
        }
        if (judge) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}