#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
//	cut here before submit 
//	freopen ("testcase.Ball", "r", stdin );
	int n;
	scanf ("%d", &n );
	rep (i, n ){
		vector<int> ball(10, 0 );
		rep (j, 10 ){
			scanf ("%d", &ball[j] );
		} // end rep
		stack<int> A, B;
		A.push (ball[0] );
		B.push (0 );
		bool ok = true;
		for (int i = 1; i < 10; i++ ){
			if (A.top() < ball[i] ){
				A.push (ball[i] );
			}else
			if (B.top() < ball[i] ){
				B.push (ball[i] );
			}else{
				ok = false;
				break;
			} // end if
		} // end for
		if (ok ){
			printf ("YES\n" );
		}else{
			printf ("NO\n" );
		} // end if
	} // end loop
		
	return 0;
}