#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>

typedef long long ll;
using namespace std;

typedef pair<int,int> P;

int main()
{
	int T;
	cin >> T;
	for(int t=0;t<T;t++){

		stack<int> stk1;
		stack<int> stk2;

		for(int i=0;i<10;i++){
			int tmp;
			cin >> tmp;
			
			if(stk1.empty() || stk1.top() < tmp) stk1.push(tmp);
			else if(stk2.empty() || stk2.top() < tmp) stk2.push(tmp);
			else {
				cout << "NO" << endl;
				goto next;
			}
		}
		cout << "YES" << endl;
next:;
	}
}