Go: package main

import "fmt"

func isOrdered(a []int) bool {
	if len(a) <= 1 {
		return true
	}
	for i := 0; i+1 < len(a); i++ {
		if a[i] > a[i+1] {
			return false
		}
	}
	return true
}

func main() {
	// ボールの数がせいぜい10個しかないので、全てのボールの落とし方を全探索することが可能
	// Bit全探索を行う。右から見てj番目のビットが立っているときには左側の筒、立っていない時は右側の筒にいれる物とする。
	// 全てのボールを落とし終わった後に、それぞれの筒で昇順に並んでいるか調べることにする。
	var t int
	fmt.Scan(&t)
	ans := make([]bool, t)
	for i := 0; i < t; i++ {
		balls := make([]int, 10)
		for i := range balls {
			fmt.Scan(&balls[i])
		}
		ans[i] = false
		for bits := 0; bits < (1 << uint(10)); bits++ {
			pipeB := make([]int, 0)
			pipeC := make([]int, 0)
			for j := 0; j < 10; j++ {
				if (bits & (1 << uint(j))) != 0 {
					pipeB = append(pipeB, balls[j])
				} else {
					pipeC = append(pipeC, balls[j])
				}
			}
			if isOrdered(pipeB) && isOrdered(pipeC) {
				// fmt.Printf("test case %d - OK pattern - pipeB %v, pipec %v\n", i, pipeB, pipeC)
				ans[i] = true
				break
			}
		}
	}
	for i := range ans {
		if ans[i] {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

C++: #include<iostream>
using namespace std;
int const N=10;
int src[N];
int a[N+1], b[N+1];//a存放左边的球，b存放右边
int aindex;//记录左边有多少球
int bindex;//右边有多少球
int ans;//标记是否能找到

void dfs(int i){//dir 标记球放在哪一边
	if (i == N){ ans = 1; return; }
	//球i放在左边
	if (src[i]>=a[aindex]){
		a[++aindex] = src[i];
		dfs(i+1);
		aindex--;
	}
	//球放在左边
	if (src[i] >= b[bindex]){
		b[bindex] = src[i];
		dfs(i + 1);
		bindex--;
	}
	return;
}
int main(){
	int n;
	cin >> n;
	while (n--){
		ans = 0;
		aindex = 0; bindex = 0;
		a[aindex] = -9999; b[bindex] = -9999;
		for (int i = 0; i < N; i++){
			cin >> src[i];
		}
		dfs(0);
		if (ans)cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

using namespace std;

const int BALL_NUM = 10;

long n;

bool IsLeft(int num, int left, int right) {
    if (left > num) { return false; }
    if (left > right || right > num) { return true; }
    else { return false; }
}

int main() {
    int b, left = 0, right = 0;
    bool flag = true;
    scanf("%ld", &n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < BALL_NUM; j++) {
            scanf("%d", &b);
            if (b < min(left, right)) {
                flag = false;
                break;
            }
            if (IsLeft(b, left, right)) { left = b; }
            else { right = b; }
        }
        if (flag) { printf("%s\n", "YES"); }
        else { printf("%s\n", "NO"); }
    }

    return 0;
}

C++: #include <stdio.h>
#include <stdbool.h>
??
#define NUM_BALL 10
??
int main(void)
{
????int???????????? n;
????int???????????? num;
????int???????????? left, right;
????bool?? flag = true;
????int???? i, j;
??
????scanf("%d", &n);
????for (i = 0; i < n; i++) {
????????????????left = right = -1;
????????????????for (j = 0; j < NUM_BALL; j++) {
????????????????????????scanf("%d", &num);
????????????????????????if?????????? (num > left) { left?? = num; }
????????????????????????else if (num > right)?????? { right = num; }
????????????????????????else?????? { flag?? = false; break; }
????????????????}
????????????????puts((flag) ? "YES" : "NO");
????????}
??
????????return 0;
}

C++: #include<iostream>
using namespace std;
int d[10]={};
bool f;
void dfs(int l,int r int s){
  if(s==10) f=true;
  //cout << d << endl;
  if(l<d[s]){
    dfs(d[s],r,s+1);
  }
  if(r<d[s]){
    dfs(l,d[s],s+1);
  }
}
int main(){
  int n;cin >> n;
  while(n--){
    int r=0,l=0,d;
    f=false;
    for(int i=0;i<10;i++){
      cin >> d;
      //cout << l << ":" << r << endl;
    }
    dfs(0,0,0);
    if(f) cout << "NO" << endl;
    else cout << "YES" << endl;
  }  
}

C++: #include<iostream>
#include<vector>
//#include<ctime>
using namespace std;
int main(){
	int n;
	cin >> n;
	//clock_t t1, t2;
	//t1 = clock();
	for(int i = 1; i <= n; i++){
		int num[10];
		for(int j = 0; j < 10; j++) cin >> num[j];
		bool flag = false;
		for(int j = 0; j < (1 << 10); j++){
			vector<int> va, vb;
			for(int k = 0; k < 10; k++){
				if(j & (1 << k)) va.push_back(num[k]);
				else vb.push_back(num[k]);
			}
			bool flag_ = true;
			for(int k = 1; k < va.size(); k++){
				if(va[k] < va[k - 1]) flag_ = false;
			}
			for(int k = 1; k < vb.size(); k++){
				if(vb[k] < vb[k - 1]) flag_ = false;
			}
			if(flag_) flag = true;
		}
		if(flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	//t2 = clock();
	//cout << t2 - t1 << endl;
	return 0;
}

C++: #include <iostream>
#include <stack>
#include <vector>
#include <algorithm>
using namespace std;
static const int MAX_N = 10;
int a[MAX_N] = {0};

bool dfs(int a[],vector<int> r,vector<int> l,int i){
	if(i==MAX_N)return true;
	if(r.size()==0 || r[r.size()-1]<a[i]){
		r.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	if(l.size()==0 || l[l.size()-1]<a[i]){
		l.push_back(a[i]);
		return dfs(a,r,l,i+1);
	}
	return false;
}


int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){//input
			cin>>a[j];
		}
		vector<int> r;
		vector<int> l;
		if dfs(a,r,l,0){
			cout<<"YES"<<endl;
		}else{
			cout<<"NO"<<endl;
		}
	}
}

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

int a[15];
int b[15],c[15];
int flag;
bool dfs(int x)
{
    if(x==10)
    return true;
    	int e,i;
	if(b[0]>c[0])
	{
		e=b[0];
		b[0]=c[0];
		c[0]=e;
	}
	if(a[x]>c[0])
	c[0]=a[x];
	else if(a[x]>b[0])
	b[0]=a[x]; 
	else 
	{
		return false;
	 } 
	dfs(x+1);
	
}
int main()
{
	int n,i,j;
	scanf("%d",&n);
	memset(b,0,sizeof(b));
	memset(c,0,sizeof(c));
	while(n--)
	{
		bool flag=false;
		for(i=0;i<10;i++)
		{
			scanf("%d",&a[i]);
		}
		flag=dfs(0);
		if(!flag) printf("NO\n");
		else printf("YES\n");
	}
}

C++: #include <cassert>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <fstream>
#include <iostream>
#include <sstream>

#include <iomanip>

using namespace std;

typedef pair<int, int> pint;
typedef vector<int> vint;
typedef long long ll;

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))

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

#define NEXTP(c) next_permutation(ALL(c))
#define SUM(c) accumulate(ALL(c),0)
#define MP( a, b ) make_pair( ( a ), ( b ) )

#define DUMP(x)  cerr << #x << " = " << (x) << endl;

#define INF 1000000000 // 10^9
const double EPS = 1e-10;
vector<int> ball;

bool dfs(int i,int left,int right){
    if (i==10) return true;
    
    if (ball[i]>left&&ball[i]>right) {
        return dfs(i+1, ball[i], right)||dfs(i+1, left, ball[i]);
    }else if(ball[i]>left&&ball[i]<right){
        return dfs(i+1, ball[i], right);
    }else if(ball[i]<left&&ball[i]>right){
        return dfs(i+1, left, ball[i]);
    }else{
        return false;
    }
    
}

int main(){
    int N;
    cin>>N;
    REP(i, N){
        ball.clear();
        ball.resize(10);
    
        REP(j, 10)cin>>ball[j];
        
        cout<<(dfs(0,0,0)?"YES":"NO")<<endl;
    }
    return 0;
}