#include <iostream>
 
using namespace std;
 
int main()
{
    int n, s, t, c, p, f;
    cin >> n;
     
    while(n--)
    {
        s = f = t = 0;
        for(int i = 0; i < 10; i++)
          {
            cin >> p;
            if(p < s && p < t){
                f = 1;
            }
                else if(p > s){
                s = p;
            } 
                else if(p > t){
                t = p;
            }  
                else {
                f = 1;
            }
        }
        if(f == 0){
            cout << "YES" << endl;
        } 
            else {
            cout << "NO" << endl;
        }
    }
     
    return 0;
}