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

int main(){
	stack<int> b,c;
	int n;
	cin>>n;

	for(int i=0;i<n;i++){
		bool flag=true;
		b.push(0);c.push(0);
		for(int j=0;j<10;j++){
			int t;
			cin>>t;
			if(b.top()<t && c.top()<t){
				if(b.top()>c.top()) b.push(t);
				else c.push(t);
			}
			else if(b.top()<t){
				b.push(t);
			}
			else if(c.top()<t){
				c.push(t);
			}
			else {
				flag=false;
			}
		}
		cout<<(flag?"YES":"NO")<<endl;

		while(!b.empty()) b.pop();
		while(!c.empty()) c.pop();
	}
	return 0;
}