#include<iostream>

using namespace std;

int main(){

  int in;
  cin >> in;
  for(int i = 0; i < in; i++){
    int data[2];
    data[0] = data[1] = 0;
    int flg = 0;
    for(int i = 0; i < 10; i++){
      int num;
      cin >> num;
      if(data[0] < data[1]){
	int tmp = data[0];
	data[0] = data[1];
	data[1] = tmp;
      }
      if(num > data[0]) data[0] = num;
      else if(num > data[1]) data[1] = num;
      else flg = 1;
    }
    if(flg) cout << "NO"<< endl;
    else cout << "YES"<<endl;
  }
  return 0;
}