#include <iostream>
using namespace std;

enum {B, C};

int main() {
	int n; cin >> n;  // ???????????????????????°
	
	while(n--){
		int balls[10] = {0};
		for(int i = 0; i < 10; i++){
			cin >> balls[i];
		}
		
		bool isYES = true;
		int top[2] = {0}; // ???B?????????C???????????¨????????????
		for(int i = 0; i < 10; i++){
			if (top[B] < balls[i]){
				top[B] = balls[i];
			} else if (top[C] < balls[i]) {
				top[C] = balls[i];
			} else {
				isYES = false;
				break;
			}
		}
		cout << (isYES ? "YES" : "NO") << endl;
	}
}