#include<iostream>
using namespace std;

int data[10];

int solve(int i, int a, int b){

  if(i == 10) return 1;

  int ans = 0;
  if(data[i] > a) ans += solve(i+1, data[i], b);
  if(data[i] > b) ans += solve(i+1, a, data[i]);

  return ans;
}

int main(){

  int n;

  cin >> n;
  while(n--){

    for(int i=0;i<10;i++) cin >> data[i];

    if(solve(0, 0, 0)) cout << "YES\n";
    else cout << "NO\n";

  }

}