#include <iostream>

using namespace std;

const int STOP = 100;

bool search(int l, int r, int* a){
	bool f = false;
	int buf = *a;
	if(buf == STOP) return true;
	if(buf < l && buf < r) return false;
	if(buf > l) f = f || search(buf, r, a + 1);
	if(buf > r) f = f || search(l, buf, a + 1);
	return f;
}

int main(){
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int l[11];
		for (int j = 0; j < 10; j++) {
			cin >> l[j];
		}
		l[10] = STOP;
		if(search(0, 0, l)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}