#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  for(int z=0; z<N; z++){
    vector<int> v(10);
    for(int i=0; i<10; i++) cin >> v[i];
    int m,n;
    if(v[0] < v[1]) m = v[0], n = v[1];
    else m = v[1], n = v[0];
    int i;
    for(i=2; i<10; i++){
      if(v[i] < m) break;
      else if(v[i] < n) m = v[i];
      else n = v[i];
    }
    if(i >= 10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}