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>

using namespace std;

int main() {

	int s=0, i, N, x[10], c=0, d=0, end1=0, end2=0;
	int a[10], b[10];

	cin >> N;
	while(N!=0) {
		for(i=0; i<10; i++)
			cin >> x[i];
		i=0;
		while(i<10) {
			if(s==0) {
				if(c==0) {
					a[c]=x[i];
					c++;
					end2=0;
				}
				if(a[c-1]>x[i]) {
					s++;
					end1=1;
				}
				else {
					a[c]=x[i];
					c++;
					end2=0;
				}
			}
			if(s==1) {
				if(d==0) {
					b[d]=x[i];
					d++;
					end1=0;
				}
				if(b[d-1]>x[i]) {
					s--;
					end2=1;
				}
				else {
					b[d]=x[i];
					d++;
					end2=0;
				}
			}
			if(end1==1&&end2==1) {
				cout << "NO" << endl;
				break;
			}
			i++;
		}
		if(end1==0||end2==0)
			cout << "YES" << endl;
		N--;
	}

	return 0;

}

C++: #include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,a;
  int b = 11,c = 11;
  cin >> n;
  while(n--){
    for(int i = 0;i < 10;i++){
      cin >> a;
      if(b > a)b = a;
      else if(c > a)c = a;
      else {
	cout << "NO" << endl;
	return;
      }  
    }
    cout << "YES" << endl;
  }
  return;
}

C++: #include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <math.h>

#define REP(i, n) for(int i = 0; i < n; i++)

using namespace std;

/*
int main(){
	int n;

	cin >> n;

	while(n--){
		int input = 0;
		int left = 0, right = 0;
		bool achieve = true;
		REP(i, 10){
			cin >> input;
			if(left > input && right > input){
				//両方入らなかったら
				achieve = false;
				break;
			}
			else{
				//どっちかにしか入らない場合
				
				if(left > input || right > input){
					//入る方探して入れる
					if(input > left){
						left = input;
					}
					else{
						right = input;
					}
				}
				//どっちにも入る場合
				else{
					//先に入ってる数字が大きい方に入れる
					if(left > right){
						left = input;
					}
					else{
						right = input;
					}
				}
			}
		}
		cout << (achieve ? "YES" : "NO") << endl;
	}
	return 0;
}
*/
int main(){
    int n;
 
    cin >> n;
    while(n--){
        int a;
        bool p = true;
        int b = 0, c = 0;
        for(int i = 0; i < 10; i++){
            cin >> a;
            if(p){
                if(a > b){
                    b = a;
                }else if(a > c){
                    c = a;
                }else{
                    p = false;
                }
            }
        }
         
        if(p){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
 
    return 0;
}

C++: #include<iostream>

int N;
int a[10];

int main()
{
	std::cin >> N;
	
	while( N-- )
	{
		for( int i = 0; i < 10; i++ )
			std::cin >> a[i];

		int lm = 0, rm = 0;

		bool f = true;

		for( int i = 0; i < 10; i++ )
		{
			if( a[i] > lm )
				lm = a[i];
			else if( a[i] > rm )
				rm = a[i];
			else 
				f = false;
		}

		if( f ) 
			std::cout << "YES" << std::endl;
		else
			std::cout << "NO" << std::endl;
	}

	return 0;
}

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

int B, C, num[12], b, c;

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

int main(void){
  int N;
  cin >> N;
  for(int j=0; j<N; j++){
  B = 0;
  C = 0;
  for(int i=0; i<10; i++){
    cin >> num[i];
  }
  dfs(0, 0, 0);
  if(dfs(0, 0, 0))  cout << "YES" << endl;
  else cout << "NO" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int k=0; k<n; k++) {
        int a[10];
        for(int i=0; i<10; i++) cin >> a[i];
        int b=-1, c=-1;
        bool f = 0;
        for(int i=0; i<10; i++) {
            if(b<a[i]) {
                b = a[i];
            } else if(c<a[i]) {
                c = a[i];
            } else {
                f = 1;
                break;
            }
        }
        printf("%s\n", f ? "NO" : "YES");
    }

    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;


const int MAX_M = 15;
int N, H[10];

double dp[2][(1 << MAX_M) + 1];

void solve() {
	int big=0, small=0;
	for (int i = 0; i < 10; i++) {
		if (big < small) swap(big, small);
		if (H[i] < small) {
			printf("NO\n");
			goto JUMP;
		}

		if (H[i] > big) big = H[i];
		else if (H[i] > small) small = H[i];

	}
	printf("YES\n");
JUMP:;
}

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 10; j++) {
			cin >> H[j];
		}
		solve();
	}

	
	return 0;
}

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

int A[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int B[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

bool isSorted(void)
{
	int i = 1;
	while(A[i]!=0 && i<=9)
	{
		if(A[i] < A[i-1]) return false;
		i++;
	}

	i = 1;
	while(B[i]!=0 && i<=9)
	{
		if(B[i] < B[i-1]) return false;
		i++;
	}

	return true;
}

int main(void)
{
	int n;
	cin >> n;
	bool enable = false;
	for(int i=0; i<n; i++)
	{
		int X[10];
		for(int j=0; j<10; j++)
			cin >> X[j];

		for(int j=0; j<1024; j++)
		{
			int a = 0, b = 0;
			int e = 1;
			for(int k=0; k<10; k++)
			{
				if( (j & e) == e)
				{
					A[a] = X[k];
					a++;
				}
				else
				{
					B[b] = X[k];
					b++;
				}
				e *= 2;
			}
			if(isSorted())
			{
				enable = true;
			}

			//initialize
			for(int j=0; j<10; j++)
			{
				A[j] = 0; B[j] = 0;
			}
		}
		if(enable) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: /**
 * 2016/8/14
 * AOJ 0033 ball
 */
#include <iostream>
#include <fstream>
using namespace std;
int n;
int Map[10];
bool solve(int begin,int left,int right){
	if (begin==10)return true;
	if(Map[begin]<left && Map[begin]<right)
		return false;
	if(Map[begin]>left && Map[begin]>right)
		return solve(begin+1,left,Map[begin]) || solve(begin+1,Map[begin],right);
	if(Map[begin]<left)
		return solve(begin+1,left,Map[begin]);
	if(Map[begin]<right)
		return solve(begin+1,Map[begin],right);
}
int main(){
	cin>>n;
	while(n--){
		//reader
		for(int i=0;i<10;++i)cin>>Map[i];
		//solver
		if(solve(0,0,0))cout<<"YES\n";
		else cout<<"NO\n";
	}
}

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

int N;
int order[10];
int l[11];
int r[11];

bool dfs(int i, int b, int c){
    
    if(i == 10)
        return true;
    
    if(order[i] > l[b-1]){
        l[b] = order[i];
        return dfs(i+1, b+1, c);
    }
        
    if(order[i] > r[c-1]){
        r[c] = order[i];
        return dfs(i+1, b, c+1);
    }  
    
    return false;
}

int main(){
    scanf("%d", &N);
    while(N--){
        
        for(int i = 0; i < 10; i++){
            scanf("%d",&order[i]);
            l[i] = -1;
            r[i] = -1;
        }
        
        if(dfs(0, 1, 1))
            printf("YES\n");
 
        else
            printf("NO\n");
    }
    return 0;
}