#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>

#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<sstream>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  int c;
  string s;

  cin >> c;
  cin.ignore();
  for (int i = 0; i < c; ++i){
    bool success = true;
    int l,r,in;
    l = r = 0;
    for(int i = 0;i < 10;i++){
      cin >> in;
      if(in > r)r = in;
      else if(in > l)l = in;
      else success = false;
    }
    cout << (success ? "YES" : "NO") << endl;
  }
  return 0;
}