#include<iostream>
#include<vector>
#include<string>
#include <algorithm>

using namespace std;

int a[10];

int main()
{
    int t;
    cin >> t;

    while(t--)
    {
        for(int i = 0; i < 10; ++i)
        {
            cin>>a[i];
        }

        vector<int> x[2];
        auto lar = &x[0];
        auto sma = &x[1];

        bool ans = true;

        for(int i = 0; i < 10; ++i)
        {
            int c = a[i];

            if(i == 0){
                lar->push_back(c);
            }
            else if(c >= lar->back())
            {
                lar->push_back(c);
            }
            else if(sma->empty())
            {
                sma->push_back(c);
                
            }
            else if(c >= sma->back())
            {
                sma->push_back(c);
                
            }
            else
            {
                ans = false;
                break;
            }
            
        }
        if(ans)
            cout<<"YES" <<endl;
        else
            cout<<"NO" <<endl;

    }
}
