#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint N;
	cin >> N;
	rep(t, N) {
		bool yes = true;
		vector<lint>A(10);
		rep(i, 10) {
			cin >> A[i];
		}
		deque<lint>B;
		deque<lint>C;
		B.push_front(0);
		C.push_front(0);
		rep(i, 10) {
			if (i == 0) {
				B.push_front(A[i]);
			}
			else {
				if (B.front() < A[i] && A[i] < C.front()) {
					B.push_front(A[i]);
				}
				else if (C.front() < A[i] && A[i] < B.front()) {
					C.push_front(A[i]);
				}
				else if (B.front() < A[i] && C.front() < A[i]) {
					if (B.front() > C.front()) {
						B.push_front(A[i]);
					}
					else {
						C.push_front(A[i]);
					}
				}
				else {
					cout << "NO" << endl;
					yes = false;
					break;
				}
			}
		}
		if (yes == true) {
			cout << "YES" << endl;
		}
	}
}
