Go: package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var num int
	fmt.Scan(&num)

	for i := 0; i < num; i++ {
		sc.Scan()
		line := sc.Text()

		insertCheck(line)
	}
}

func insertCheck(line string) {
	var B, C []int

	for _, v := range strings.Split(line, " ") {
		ball, _ := strconv.Atoi(v)
		switch {
		case len(B) == 0:
			B = append(B, ball)
		case B[len(B)-1] < ball:
			B = append(B, ball)
		case B[len(B)-1] >= ball:
			switch {
			case len(C) == 0:
				C = append(C, ball)
			case C[len(C)-1] < ball:
				C = append(C, ball)
			case C[len(C)-1] >= ball:
				fmt.Println("NO")
				return
			}
		}
	}
	fmt.Println("YES")
}

C++: #include <stdio.h>

#include <stack>

int main(void){
    using namespace std;
    stack<int> a,b;
    int n,j,i,ball,flag=0;
    scanf("%d",&n);
    for(j=0; j<n; j++){
        for(i=0; i<10; i++){
            scanf("%d",&ball);
            if(a.empty()){
                a.push(ball);
            }else if(a.top() < ball){
                a.push(ball);
            }else if(b.empty()){
                b.push(ball);
            }else if(a.top() < ball){
                b.push(ball);
            }else{
                flag=1;
            }
        }
        if(flag==0){
            printf("YES\n");
        }else{
            printf("NO\n");
        }
    }
    return 0;
}

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

using namespace std;

int N;
int l[15];
int b,c;
//int res[1000000000000];


void solve(int k){
  for(int i=0;i<10;i++){
    if(b<l[i] && c<l[i]){
      if(l[i]-b < l[i]-c) b=l[i];
      else c=l[i];
    }
    else if(b<l[i] && c>l[i]) b=l[i];
    else if(b>l[i] && c<l[i]) c=l[i];
    else{
  //    res[k]=0;
      printf("NO\n");
      return;
    }
  }
  printf("YES\n");
  return;
}


int main(){
  scanf("%d",&N);

  for(int i=0;i<N;i++){
    b=0;
    c=0;
    scanf("%d%d%d%d%d%d%d%d%d%d",&l[0],&l[1],&l[2],&l[3],&l[4],&l[5],&l[6],&l[7],&l[8],&l[9]);
    solve(i);
  }

  /*for(int i=0;i<N;i++){
    if(res[i]==0) printf("NO\n");
    else printf("YES\n");
  }
*/

  return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
  int n, num, max, min;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    max = 0;
    min = 0;
    flag = true;
    for(int j = 0; j < 10; j++){
      cin >> num;

      if(max < num){
        max = num;
      }else if(min > num){
        min = num;
      }

      if(20 - (max + min) < 10 - j + 1) flag = false;
    }

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

C++: #include<stdio.h>

//引数はそれぞれ、入力配列のカウント変数、a[]のカウント変数,b[]のカウント変数,答え配列,筒を意味するaとb配列,成功判定flg変数
bool tansaku(int count,int n1,int n2,int ans[],int a[],int b[],bool flg)
{
	//カウントが１０になったときは成功したとき
	if (count == 10)
	{
		return true;
	}
	//既にflgがtrueならさっさと返す
	if (flg == false)
	{
		//最初はn1は１である
		if (a[n1] < ans[count])		//１つ前の要素と比べている
		{
			//a[n1]にans[count]を格納
			//最初に足しておくと動作が正しくなる
			n1++;					
			//答えを格納
			a[n1] = ans[count];
			//入力された配列に使うカウント変数
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合falseで上書きしないように調整
			if (hozon == true)
			{
				flg = true;
			}
		}
		//ひとつ前の要素と比べている
		if (b[n2] < ans[count])
		{
			//先に足す
			n2++;
			//b[n2](最初はn2 = 1)に小さい順に入れていく
			b[n2] = ans[count];
			//関数の前でインクリメント
			count++;
			//再帰関数
			bool hozon = tansaku(count,n1,n2,ans,a,b,flg);
			//trueだった場合上書きしないようにする
			if (hozon == true)
			{
				flg = true;
			}
		}
	}

	return flg;
}


int main(void)
{
	//何回回すか
	int n = 0;
	//10個のボール
	int a[10] = {0};
	//関数で送るためのいらない変数
	int damy[20] = {0};
	bool ans_flg[100] = {false};

	scanf("%d",&n);
	//n回文の入力
	for (int i = 0;i < n;i++)
	{
		scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9]);
		if (tansaku(0,0,0,a,damy,damy,false) == true)
		{
			ans_flg[i] = true;
		}
	}

	for (int i = 0;i < n;i++)
	{
		if (ans_flg[i] == true)
		{
			printf("YES\n");
		}
		else
		{
			printf("NO\n");
		}
	}

	return 0;
}

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

int Data[10];

bool dfs(int a,int left,int right) {
	//cout << a << "/" << left << "/" << right << endl;
	if (a == 10) return true; 
	if (Data[a] > left) {
		//Add a to the left
		if(dfs(a+1,a,right)) return true;
	}
	else if (Data[a] > right) {
		//Add a to the right
		if(dfs(a+1,left,a)) 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 >> Data[j];
		}
		if(dfs(0,0,0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

int N;
int tama[11];

bool dfs(int x, int l, int r){
	if(x==10) 	return true;
	if(tama[x]>l)	dfs(x+1,tama[x],r);
	else if(tama[x]>r) dfs(x+1,l,tama[x]);
	else return false;
}

int main(){
	cin >> N;
	while(N--){
		for(int i=0;i<10;i++)
			cin >> tama[i];
		if(dfs(0,0,0))	cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

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

int balls[10];

int dfs(int i, int a, int b){
	if(i >= 10)
		return 1;
	
	int res = 0;
	if(a < balls[i])
		res |= dfs(i + 1, balls[i], b);
	if(b < balls[i])
		res |= dfs(i + 1, a, balls[i]);
	return res;
}

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < 10; ++j)
			scanf("%d", &balls[j]);
		int ans = dfs(0, 0, 0);
		if(ans)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}

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

int Balls[10];

bool dfs(int i, int R, int L)
{
	if(i == 10) return true;

	if(dfs(i+1, Balls[i], L) && Balls[i] > R) return true;

	if(dfs(i+1, R, Balls[i]) && Balls[i] > L) return true;

	return false;
}

void main()
{
	int n;

	cin >> n;
	for(int i=0; i<n; i++){
		for(int j=0; j<10; j++)
			cin >> Balls[j];

		if(dfs(0, 0, 0)) cout << "YES\n";
		else cout << "NO\n";
	}

	return 0;
}

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

int b[10], l, r;

void check(){
    l = r = 0;
    int i;
    for(i = 0; i < 10; i++){
        if( b[i] < l && b[i] < r ) break;
        else if( b[i] < l ){
            r = b[i];
        }else if( b[i] < r ){
            l = b[i];
        }else if( l < r ){
            r = b[i];
        }else{
            l = b[i];
        }
    }
    if( i == 10 ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}

int main(){
    int n;
    cin >> n;
    while(n-- > 0){
        for(int i = 0; i < 10; i++){
            cin >> b[i];
        }
        check();
    }
    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <complex>
#include <functional>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(c,i) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

string solve(int a[])
{
	int box[2]={0};
	rep(i,10){
		if(box[box[0]<box[1]]<a[i])
			box[box[0]<box[1]]=a[i];
		else if(box[box[0]>box[1]]<a[i])
			box[box[0]>box[1]]=a[i];
		else
			return "NO";
	}
	return "YES";
}

int main()
{
	int n;
	cin>>n;
	rep(loop,n){
		int a[10];
		rep(i,10)
			cin>>a[i];
		cout<<solve(a)<<endl;
	}
	
	return 0;
}