#include <iostream>
using namespace std;
bool canbe = false;
int inp[10];

void dfs(int b, int c, int depth){
    if (depth >= 10){
	canbe = true; return;
    }
    if (inp[depth] < b && inp[depth] < c) return;

    if (inp[depth] > b) dfs(inp[depth], c, depth+1);
    if (inp[depth] > c) dfs(b, inp[depth], depth+1);
}


int n;
int main(){
    cin >> n;
    for (int i = 0; i < n; i++){
	canbe = false;
	for (int j = 0; j < 10; j++) cin >> inp[j];
	
	dfs(0, 0, 0);

	if (canbe) cout << "YES" << endl;
	else cout << "NO" << endl;
    }
}