#include <iostream>
#include <vector>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<int> d(10);
	int b, c;

	for (int i = 0; i<N; i++){
		for (int k = 0; k < 10; k++)
			cin >> d.at(k);

		b = d.at(0);
		c = 0;
		for (int k = 1; k < 10; k++){
			if (b < c){
				if (b > d.at(k)){
					cout << "NO" << endl;
					break;
				}
				else{
					if (c < d.at(k))
						c = d.at(k);
					else
						b = d.at(k);
				}
			}

			else{
				if (c > d.at(k)){
					cout << "NO" << endl;
					break;
				}
				else{
					if (b < d.at(k))
						b = d.at(k);
					else
						c = d.at(k);
				}
			}
			if (k == 9)
				cout << "YES" << endl;
		}
	}
}
