#include<iostream>
using namespace std;

int a[15], b[2], flag[2];

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int is_yes = 1;
        b[0] = b[1] = 0;
        for(int i = 0; i < 10; i++)
            cin >> a[i];
        for(int i = 0; i < 10; i++)
        {
            flag[0] = flag[1] = 0;
            for(int j = 0; j < 2; j++)
            {
                //cout << "a[i]" << a[i] << endl;
                if(b[j] == 0)
                {
                    b[j] = a[i];
                    break;
                }
                else if(b[j] < a[i])
                {
                    b[j] = a[i];
                    break;
                }
                flag[j] = 1;
            }
            //for(int j = 0; j < 2; j++)
                //cout << "b[" << j <<"] = " << b[j] << endl;
            if(flag[1] && flag[0])
            {
                cout << "NO" << endl;
                is_yes = 0;
                break;
            }
        }
        if(is_yes)
            cout << "YES" << endl;
    }


    return 0;
}

