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"
#include"stdio.h"
using namespace std;
int ball[11];
bool flag;
 
void Dfs(int i,int left,int right)
{
    if(flag) return;
    if(i==10) {flag=true;return;}
 
    if(ball[i]>left)
        Dfs(i+1,ball[i],right);
    if(ball[i]>right)
        Dfs(i+1,left,ball[i]);
}
 
int main()
{
    int t;
    while(scanf("%d",&t)==1)
    {
        while(t--){
            flag=false;
            for(int i=0;i<10;i++)
                cin>>ball[i];
            Dfs(0,0,0);
            if(flag)
                cout<<"YES"<<endl;
            else
                cout<<"NO"<<endl;
        }
    }
    return 0;
}

C++: #include<iostream>

using namespace std;

int main(){
	int N;

	cin >> N;

	for (int i = 0; i < N; i++){
		int  b = 1, c = 1;
		int num[10];
		int B[11] = { 0 }, C[11] = { 0 };
		bool flag = false;
		

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

		for (int i = 0; i < 10; i++){
			if (B[b-1] < num[i]){
				//cout << "B" << B[b-1] << ' '<< num[i]<< endl;
				B[b] = num[i];
				b++;
			}
			else{
				//cout << "C" << C[c - 1] << ' ' << num[i] << endl;
				if (C[c-1] < num[i]){
					C[c] = num[i];
					c++;
				}
				else{
					flag = true;
					break;
				}

			}
		}

		if (flag == false) cout << "YES" << endl;
		if (flag == true) cout << "NO" << endl;
	}
}

C++: #include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int n;
    cin >> n;
    rep(i, n){
        vector<int> b, c;
        b.push_back(-1);
        c.push_back(-1);
        bool flag = true;
        rep(j, 10){
            int a;
            cin >> a;
            if(flag){
                if(b[b.size()-1] < c[c.size()-1]){
                    if(c[c.size()-1] < a){
                        c.push_back(a);
                    }else if(b[b.size()-1] < a){
                        b.push_back(a);
                    }else{
                        flag = false;
                    }
                }else{
                    if(b[b.size()-1] < a){
                        b.push_back(a);
                    }else if(c[c.size()-1] < a){
                        c.push_back(a);
                    }else{
                        flag = false;
                    }
                }
            }
        }
        if(flag){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
    }
    return 0;
}

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

int num[10];

bool f;
void dfs(int x, int l, int r) {
	if (x == 10) {
		f = true;
	}
	if (num[x] > l) {
		dfs(x + 1, num[x], r);
	}
	if (num[x] > r) {
		dfs(x + 1, l, num[x]);
	}
}

int main() {
	int T;
	cin >> T;
	cin.ignore();
	while (T--) {
		string line;
		getline(cin, line);
		stringstream ss(line);
		for (int i = 0; i < 10; i++) {
			ss >> num[i];
		}
		f = false;
		dfs(0, 0, 0);
		if (f) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn=1009;
int a[maxn];
int b[maxn];
int c[maxn];
int ln,lm,flag;
int t;
bool erjinzhi()
{
    for(int i=0;i<1024;i++)
    {
        memset(b,0,sizeof(b));
        memset(c,0,sizeof(c));
        ln=0;
        lm=0;
        flag=1;
        for(int j=i,cnt=0;cnt<10;cnt++,j>>=1)
        {
            if(j&1)
            b[ln++]=a[cnt];
            else
            c[lm++]=a[cnt];
        }
        for(int k=1;k<ln;k++)
        {
            if(b[k-1]>b[k])
            {
                flag=0;
                break;
            }
        }
        if(flag)
        for(int k=1;k<lm;k++)
        {
            if(c[k-1]>c[k])
            {
                flag=0;
                break;
            }
        }
        if(flag)return true;
    }
    return false;
}
int main()
{
    scanf("%d",&t);
    while(t--)
    {

     for(int i=0;i<10;i++)
     scanf("%d",&a[i]);
     bool fl=erjinzhi();
     if(fl)
     printf("YES\n");
     else
     printf("NO\n");
    }
    return 0;
}

C++: #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	int n;
	while (n--){
	bool yes=true;
		stack<int> s1;
		stack<int> s2;
		s1.push(0);
		s2.push(0);
		REP(i, 10){
			int a;
			cin >> a;
			if (s1.top() <= s2.top()){
				if (s1.top() < a)
					s1.push(a);
					continue;
			}
			if (s2.top() < a){
					s1.push(a);
					continue;
			}
			yes=false;

		}
		if (yes)
			cout << "YES"<<endl;
			else
				cout << "NO" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <algorithm>
#define HEIGHT 10

using namespace std;

int a[HEIGHT];
/*
void solve(){
	bool f=true;
	int right,left;
	right = left = 0;
	for(int i=0;i<HEIGHT;i++){
		if(right<a[i] && left<a[i]){
			if(right<left){
				left = a[i];
			} else {
				right = a[i];
			}
		} else if(right<a[i]){
			right = a[i];
		} else if(left<a[i]){
			left = a[i];
		} else {
			f = false;
			break;
		}
	}
	if(f) printf("YES");
	else printf("NO");
}*/

bool back(int right, int left, int n){
	if(n == 10) return true;
	bool result = false;
	if(right<a[n]) result = result || back(a[n],left,n+1);
	if(left<a[n]) result = result || back(right,a[n],n+1);
	return result;
}

void solve(){
	if(back(0,0,0)) printf("YES");
	else printf("NO");
}
			
int main(){
	
	int lp;
	scanf("%d",&lp);
	
	for(int i=0;i<lp;i++){
		for(int j=0;j<HEIGHT;j++){
			scanf(" %d",&a[j]);
		}
		solve();	
	}
	return 0;
}