#include <iostream>
using namespace std;

const int N = 10;
int a[N];
      
int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    for(int i = 0; i < N; ++i) cin >> a[i];
    string res = "NO";
    for(int b = 0; b < (1<<N); ++b) {
      int pre[2] = {-1,-1};
      for(int i = 0; i < N; ++i) {
	int t = ((b>>i)&1);
	if(pre[t] != -1 && pre[t] > a[i]) {
	  break;
	}
	pre[t] = a[i];
	if(i+1 == N) res = "YES";
      }
    }
    cout << res << endl;
  }
  return 0;
}