#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>
#include <cstdlib>

typedef long long ll;

using namespace std;

struct ToLower {    char operator()(char c) { return tolower(c); }};

int main(void){
	int N;
	cin >> N;

	int ball[10];
	int a=0, b=0;
	int check = 0;

	for(int i=0; i<N; ++i){
		a=0, b=0, check=0;

		for(int j=0; j<10; j++){
			cin >> ball[j];
		}
		for(int j=0; j<10; ++j){
			if(ball[j] > a && ball[j] > b){
				(a > b ? a : b) = ball[j];
				continue;
			} else if(ball[j] < a && ball[j] < b){
				cout << "NO" << endl;
				check = 1;
				break;
			} else {	
				(a < b ? a : b) = ball[j];
			}
		}
		if(check == 0) cout << "YES" << endl;

	}
	return 0;
}