#include <bits/stdc++.h>
using namespace std;

signed main(void)
{
  stack<int> b, c;
  int n;
  int B, C = 0;

  cin >> n;

  for (int j = 0; j < n; j++){
    bool frag = true;
    int a[10];
    for (int k = 0; k < 10; k++) cin >> a[k];
   
    for (int i = 0; i < 10; i++){
      if (i == 0) {
        B = a[i];
        b.push(a[i]);
      }
      else if (B > a[i] && C < a[i]) {
        C = a[i];
        c.push(a[i]);
      }
      else if (B < a[i]) {
        B = a[i];
        b.push(a[i]);
      }
      else {
        frag = false;
        break;
      }
    }
    if (frag) puts("YES");
    else puts("NO");
  }

  return 0;
}