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

int main(){
    int n;
    cin >> n;
    for (int i = 0; i < n; i++){
	
	stack<int> b, c;
	b.push(0); c.push(0);
	bool canBeSorted = true;

	int g;
	for (int j = 0; j < 10; j++){
	    cin >> g;
	    if (g <= b.top() && g <= c.top()){ canBeSorted = false; break; }
	    if (g - b.top() <= g - c.top() && g - b.top() > 0) b.push(g);
	    else c.push(g);
	}

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