#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n, ball[10];
  vector<string> result;

  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++)
      cin >> ball[j];
    int j, a = 0, b = 0;
    for (j = 0; j < 10; j++) {
      if (ball[j] > a)
        a = ball[j];
      else if (ball[j] > b)
        b = ball[j];
      else
        break;
    }
    if (j == 10)
      result.push_back("YES");
    else
      result.push_back("NO");
  }

  for (int i = 0; i < n; i++)
    cout << result[i] << endl;
  return 0;
}