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<iostream>
#include<vector>
#include<stack>

#define rep(i,a) for(int i=0;i<(a);i++)
using namespace std;

vector<int> in;


bool check(vector<int> r,vector<int> l){
	int lenr=r.size(),lenl=l.size();
	for(int i=1;i<lenr;i++){
		if(r[i]<=r[i-1])return false;
	}	
	for(int i=1;i<lenl;i++){
		if(l[i]<=l[i-1])return false;
	}
	return true;
}

bool dfs(vector<int> r,vector<int> l,int num){
	if(!check(r,l))return false;
	if(num==10)return true;

	r.push_back(in[num]);
	if( dfs(r,l,num+1) )return true;
	r.pop_back();

	l.push_back(in[num]);
	if( dfs(r,l,num+1) )return true;
	l.pop_back();

	return false;
}



int main(){
int N;
	cin>>N;
	rep(roop,N){
        while(in.size())in.pop_back();
		rep(i,10){
			int tmp;
			cin>>tmp;
			in.push_back(tmp);
		}
		if(dfs({},{},0))	cout<<"YES"<<endl;
		else		cout<<"NO"<<endl;	
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

bool judge(int num){
	int i, n, q[2]={0,0};

	for (i=0; i<num; i++) {
		cin >> n;
		if (q[0]<n)
			q[0] = n;
		else if (q[1]<n)
			q[1] = n;
		else
			break;
	}

	return ((i==num)? true: false);
}

int main(){
	int i, n;

	cin >> n;
	for (i=0; i<n; i++)
		cout << (judge(10)? "YES": "NO") << endl;

	return 0;
}

C++: #include <cmath>
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    bool flag;
    int num;
    int a,b,t;
    cin >> t;
    while(t--)
    {
        b = 0;
        flag = true;
        for(int i = 0; i < 10; i++)
        {
            scanf("%d",&num);
            if(i == 0)
            {
                a = num;
                continue;
            }
            if(num < a)
            {
                if(num > b)
                {
                    b = num;
                    continue;
                }
                else
                {
                    flag = false;
                    break;
                }
            }
            else if(num > a)
            {
                if(num-a > num-b)
                {
                    b = num;
                    continue;
                }
                else
                {
                    a = num;
                    continue;
                }
            }
        }
        if(flag == true)
        {
            printf("YES\n");
        }
        else printf("NO\n");
        fflush(stdin);
    }
    return 0;
}

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

int balls[10];

bool dfs(int i=0,int b_top=0,int c_top=0){
  //10個のボールを落とせたらtrue
  if(i == 10) return true;
  
  //Bのほうに入れる
  if(balls[i] > b_top && dfs(i+1,balls[i],c_top))
    return true;

  //Cの方に入れる
  if(balls[i] > c_top && dfs(i+1,b_top,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];
    cout << (dfs() ? "YES":"NO") << endl;
  }
  return 0;
}

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


int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		int ball[10];
		for(int j=0;j<10;j++)scanf("%d",&ball[j]);
		
		stack<int> S,Q;
		int a[2]={0};
		a[0] = ball[0];
		S.push(a[0]);
		Q.push(a[1]);
		
		int k=1;
		bool OK = false;
		while(1){
			a[0] = S.top();
			a[1] = Q.top();
			if(a[0] < ball[k]){
				S.push(ball[k]);
				k++;
				if(k >= 10){
					OK = true;
					break;
				}
			}else if(a[1] < ball[k]){
				Q.push(ball[k]);
				k++;
				if(k >= 10){
					OK = true;
					break;
				}
			}else{
				S.pop();
				Q.pop();
				k--;
			}
			if(S.size() == 0) break;
		}		
		if(OK == true) printf("YES\n");
		else printf("NO\n");
		
	}
	return 0;
}

C++: #include<iostream>

int a[10];
bool J;

void dfs(int n,int left,int right){
	if(n==10)
		J=true;
    if(a[n]>left)
			dfs(n+1,a[n],right);
    if(a[n]>right)
			dfs(n+1,left,a[n]);
}

int main(){
	int N;
	std::cin>>N;
	for(int i=0;i<N;++i){
		for(int i=0;i<10;++i){
			std::cin>>a[i];
		}
		J=false;
		dfs(0,0,0);
		if(J==true)
			std::cout<<"YES"<<std::endl;
		else std::cout<<"NO"<<std::endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)

int a[10];

//B:=B?????????????????° C*=C?????????????????° cnt:=??????????????°??????
bool dfs(int B, int C, int cnt){
    if(cnt == 10){
        return true;
    }
    if(B < a[cnt]){
        return dfs(a[cnt], C, cnt + 1);
    }
    if(C < a[cnt]){
        return dfs(B, a[cnt], cnt + 1);
    }
    if(B > a[cnt] && C > a[cnt]){
        return false;
    }
}
int main(void){
    int n; cin >> n;
    for (int i = 0; i < n; ++i){
        rep(j, 10) cin >> a[j];
        if(dfs(0, 0, 0)) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}

C++: #include<cstdio>
#include<iostream>
int mitaball(int n,int Bn,int Cn);
int ball[10],B[10]={0},C[10]={0};
int judge;
int a;
int x;
int main(){
    scanf("%d",&x);
    for(int j=0;j<x;j++){
        judge=0;
        for(int i=0;i<10;i++)
            scanf("%d",&ball[i]);
        mitaball(0,0,0);
        if(judge==1)
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}
int mitaball(int n,int Bn,int Cn){
    if(judge==0){
        if(n==10){
            for(int i=0;i<Bn-1;i++){
                if(B[i]>B[i+1])
                    break;
                judge=1;
            }
            for(int i=0;i<Cn-1;i++){
                if(C[i]>C[i+1]||judge==0)
                    break;
                judge=1;
            }
        }
        else{
            B[Bn]=ball[n];
                mitaball(n+1,Bn+1,Cn);
            B[Bn]=0;
            C[Cn]=ball[n];
                mitaball(n+1,Bn,Cn+1);
            C[Cn]=0;
        }
    }
}

C++: #include <bits/stdc++.h>

#define SIZE 300005
#define MOD 1000000007LL
#define INF INT_MAX / 3
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int a[10];

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

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  REP(v,n)
  {
    REP(i,10) cin >> a[i];
    cout << (dfs(0,0,0)?"YES":"NO") << "\n";
  }
  return 0;
}