Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n := nextInt()
	for i := 0; i < n; i++ {
		a := -1
		b := -1
		ans := true
		// それぞれの筒の一番上にあるたまの数字に着目すればよい
		for j := 0; j < 10; j++ {
			x := nextInt()
			if x > a {
				a = x
			} else if x > b {
				b = x
			} else {
				ans = false
			}
		}
		if ans {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
int main(){
  int n,date;
  int sta[2];
  cin >> n;
  while(n--){
    bool f = true;
    sta[0] = 0;
    sta[1] = 0;
    for(int i = 0;i < 10 ; i++){
      cin >> date;
      if(date > sta[0])sta[0] = date;
      else if(date > sta[1])sta[1] = date;
      else f = false;
    }
    if(f)puts("YES");
    else puts("NO");
  }
  return 0;
}

C++: #include <iostream>

using namespace std;


int main(){

	int n, A, B, C;
	bool ans;

	cin >> n;

	while (n--){
		ans = 1;
		B = 0;
		C = 0;

		for (int i = 0; i < 10; i++){
			cin >> A;

			if (A > B){
				B = A;
			}
			else if(A > C){
				C = A;
			}
			else{
				ans = 0;
				break;
			}
		}

		cout << (ans ? "YES" : "NO") << endl;

	}


	return 0;
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  int ball[100][10],count=0;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ball[i][j];
    }
    for(int j=0;j<6;j++){
      if(ball[i][j] > ball[i][j+2] || ball[i][j+1] > ball[i][j+3]){
	cout << "NO" << endl;
	  count++;
	  break;
      }
    }
    if(count == 0){
      cout << "YES" << endl;
    }
    count=0;
  }
}

C++: #include<iostream>
int box[10];
int ltop=-1,rtop=-1;
bool ball(int i){
	if(i==9)return true; 
	if(ltop==-1 || rtop==-1){
		if(ltop==-1){
			ltop=box[i];
			return ball(i+1);
		}
		else{
		    rtop=box[i];
			return ball(i+1);	
		}
	}
	else{
		if(box[i]>ltop&&box[i]>rtop){
			if(ltop>rtop){
				ltop=box[i];
			}
			else{
				rtop=box[i];
			}
			return ball(i+1);
		}
		else if(box[i]>ltop){
			ltop=box[i];
			return ball(i+1);
		}
		else if(box[i]>rtop){
			rtop=box[i];
			return ball(i+1);
		}
		else return false;
	}
}
int main(){
	int n;
	std::cin>>n;
	for(int what=0;what<n;++what){
		for(int i=0;i<10;++i){
			std::cin>>box[i];
		}
		if(ball(0))std::cout<<"YES\n";
		else std::cout<<"NO\n";
	}
}

C++: #include <iostream>
using namespace std;

int Balls[10];

bool fork(int balls[], int i, int b, int c) {
  if (i == 10) return true;
  if (b > balls[i] && c > balls[i]) return false;
  if (b < balls[i] && fork(balls, i + 1, balls[i], c)) return true;
  if (c < balls[i] && fork(balls, i + 1, b, balls[i])) return true;
  return false;
}

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> Balls[j];
    }
    if(fork(Balls, 0, 0, 0)) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <array>

using namespace std;

int main()
{
        int set_number, L, R, flag = 0;
        cin >> set_number;
        array< int, 10 > ar;

        for ( int i = 0 ; i < set_number ; i++ )
        {
                for ( int j = 0 ; j < 10 ; j++ )
                {
                        cin >> ar[j];
                }

                L = ar[0];
                R = 0;
                for ( int j = 1 ; j < 10 ; j++ )
                {
                        if ( L < ar[j] )
                        {
                                L = ar[j];
                        }
                        else if ( L > ar[j] )
                        {
                                if ( R < ar[j] )
                                {
                                        R = ar[j];
                                }
                                else
                                {
                                        fprintf( stdout, "No\n" );
                                        flag = 1;
                                        break;
                                }
                        }
                }

                if ( flag == 0 )
                {
                        fprintf( stdout, "Yes\n" );
                }
        }

        return 0;
}

C++: #include<iostream>
main(){
int n,i,A,B,C,f;
for(std::cin>>n;n-->0;puts(f?"NO":"YES"))
 for(B=C=f=i=0;i<10;i++){
  std::cin>>A;
  if(B<A)B=A;
  else C<A?C=A:f=1;
 }
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,j,k) for(int i = j;i<k;i++)
int N;
int A[10];
bool DFS(int Aindex,int x,int y){
  if(Aindex ==10)return true;
  if(x>A[Aindex] && y>A[Aindex])return false;
  bool m=false;
  if(x<A[Aindex])m=max(m,DFS(Aindex+1,A[Aindex],y));
  if(y<A[Aindex])m=max(m,DFS(Aindex+1,x,A[Aindex]));
  return m;
}
int main(){
  cin >> N;
  string ans[2]={"NO","YES"};
  rep(i,0,N){
    rep(i,0,10){
      cin >>A[i];
    }
    cout << ans[DFS(0,0,0)]<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;

int main() {
    int n; cin >> n;  
    while(n--){
        int balls[10] = {0};
        for(int i = 0; i < 10; i++){ cin >> balls[i]; }
        
        bool isYES = true;  
        int topB = 0, topC = 0; 
        for(int i = 0; i < 10; i++){
            if (topB < balls[i]){
                topB = balls[i];
            } else if (topC < balls[i]) {
                topC = balls[i];
            } else {
                isYES = false;
                break;
            }
        }
        cout << (isYES ? "YES" : "NO") << endl;
    }
}

C++: #include<iostream>
using namespace std;
bool solve(int, int, int);
int a[10];

int main(void){
	int n;
	char t;
	bool flag;
	cin >> n;
	do{
		n--;
		cin >> a[0];
		for(int i = 1; i < 10; i++){
			cin >> t >> a[i];
		}
		if(solve(0,0,0)){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}while(n != 0);
	return 0;
}

bool solve(int i, int b, int c){
	if(i == 9){
		if(a[i] > b || a[i] > c)
			return (true);
		return(false);
	}
		if(solve(i + 1, a[i], c) || solve(i + 1, b, a[i])){
			return (true);
		}
	return (false);
}

C++: #include<iostream>
using namespace std;
 
int data[10];
 
bool solve(int i, int a, int b){
 
  if(i == 10) return true;
 
  if(data[i] > a) return solve(i+1, data[i], b);
  if(data[i] > b) return solve(i+1, a, data[i]);
  
  return false;
}
 
int main(){
 
  int n;
 
  cin >> n;
  while(n--){
 
    for(int i=0;i<10;i++) cin >> data[i];
 
    cout << (solve(0, 0, 0)?"YES\n":"NO\n");
 
  }
 
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N=in();
	LOOP(N){
		auto V=vecin(10);
		vector<int> B,C;
		bool success = true;
		REP(i,10){
			if(B.empty() || B.back()<V[i]){
				B.push_back(V[i]);
			}
			else if(C.empty() || C.back()<V[i]){
				C.push_back(V[i]);
			}
			else{
				success = false;
				break;
			}
		}

		out(success?"YES":"NO");
	}
	return 0;
}