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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
template<typename V> typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();

// clang-format on

bool dfs(vi v, int l, int r) {
  if (v.size() == 0) {
    return true;
  }
  bool hoge = false;
  if (v.back() > l) {
    vi _v  = v;
    int _l = v.back();
    _v.pop_back();
    hoge |= dfs(_v, _l, r);
  }
  if (v.back() > r) {
    vi _v  = v;
    int _r = v.back();
    _v.pop_back();
    hoge |= dfs(_v, l, _r);
  }
  return hoge;
}

main {
  int n;
  cin >> n;
  rep(_, n) {
    vi v(10);
    rep(i, 10) cin >> v[9 - i];
    cout << (dfs(v, 0, 0) ? "YES" : "NO") << endl;
  }
  return 0;
}

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

string func(stack<int>,stack<int>,stack<int>);

int main(){
		  stack<int> s,st,right,left;
		  int loop,num;

		  cin>>loop;
		  for(int i=0;i<loop;i++){

					 while(!s.empty()) s.pop();
					 while(!st.empty()) st.pop();
					 while(!right.empty()) right.pop();
					 while(!left.empty()) left.pop();
					 right.push(0);left.push(0);

					 for(int l=0;l<10;l++){
								cin>>num;
								s.push(num);
					 }
					 while(!s.empty()){
								st.push(s.top());
								s.pop();
					 }

					 cout<<func(st,right,left)<<endl;
		  }
		  return 0;
}

string func(stack<int> st,stack<int> right, stack<int> left){
		  if(st.empty()) return "YES";

		  if(right.top()<st.top()){
					 right.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(right.top());
								right.pop();
					 }
		  }
		  if( left.top()<st.top()){
					 left.push(st.top());
					 st.pop();
					 if(func(st,right,left)=="YES") return "YES";
					 else{
								st.push(left.top());
								left.pop();
					 }
		  }

		  return "NO";
}

C++: #include <iostream>
using namespace std;
int main(){
int a;
int b;
int n;
int c;
int d;
int e;
int f;
cin >>n;
c=0;
while(c<n){
f=0;
a=0;
b=0;
d=0;
while(d<10){
cin >>e;
if(e>a&&a>b){a=e;}
else if(e>b&&b>a){b=e;}
else if(e>a){a=e;}
else if(e>b){b=e;}
else{f=1; break;}
d=d+1;}
if(f==0){cout <<"YES"<<endl;}
if(f==1){cout <<"NO"<<endl;}
c=c+1;}}

C++: #include<iostream>
#include<cstring> 
using namespace std;
int a[10];
bool vis[10];
int main(){
	int t;
	cin>>t;
	while(t--){
		memset(vis, 0, sizeof vis);
		for(int i = 0; i < 10; i++) cin>>a[i];
		int now = 0;
		for(int i = 1; i < 10; i++){
			if(a[i] > a[now]){
				now = i;
				vis[now] = 1;
			}
		}
		bool flag = true;
		now = -1;
		for(int i = 1; i < 10; i++){
			if(!vis[i]){
				if(now == -1) now = i;
				else{
					if(a[i] < a[now]){
						flag = false;
						break;
					}
					else now = i;
				}
			}
		}
		if(flag) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include<stdio.h>
int main(void)
{
	int n,i,sum,t,aaa,bbb,nnn;
	char ch,a[10000];
	scanf("%d",&n);
	getchar();
	while(n--)
	{
		t=0;i=0;
		sum=0;aaa=0;bbb=0;
		while((ch=getchar())!='\n')
			a[i++]=ch;
		nnn=i;
		for(i=0;i<nnn;i++)
		{
			if(a[i]>='1'&&a[i]<='9')
			{
				if(a[i+1]=='0')
					sum=10,i++;
				else
					sum=a[i]-'0';
				if(aaa==0)
					aaa=sum;
				else
				{
					if(aaa<sum&&bbb<sum)
						t=1;
					if(aaa>sum)
						bbb=sum;
					else
					{
						if(bbb>sum)
							aaa=sum;
						else
						{
							if(aaa>bbb)
								aaa=sum;
							else
								bbb=sum;
						}
					 } 
				}
			}
			
		}
		if(t==1)
			printf("YES\n");
		else
			printf("NO\n");
	}
}

C++: #include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
using namespace std;

#define REP(i,n) for ( int i = 0; i < (int)n; i++ )
#define FOR(i,c) for ( __typeof((c).begin())i=(c).begin(); i != (c).end(); i++ )
#define ALL(c) (c).begin(), (c).end()

typedef vector <int> VI;
int a, b;

bool solve( VI L, int d ) {
  if ( d >= (int)L.size() ) {
    return true;
  }
  int ba = a;
  int bb = b;
  if ( L[d] > a ) {
    a = L[d];
    if ( solve( L, d + 1 ) ) return true;
    a = ba;
  }
  if ( L[d] > b ) {
    b = L[d];
    if ( solve( L, d + 1 ) ) return true;
    b = bb;
  }
  return false;
}

int main() {
  int n;
  while ( cin >> n ) {
    for ( int i = 0; i < n; ++ i ) {
      VI L( 10 );
      for ( int j = 0; j < 10; ++ j ) {
	cin >> L[j];
      }
      a = 0;
      b = 0;
      cout << ( solve( L, 0 ) ? "YES" : "NO" ) << endl;
    }
  }
  return 0;
}

C++: #include<iostream>
#include<stack>
using namespace std;
int main(){
  int N;
  cin >> N;
  int boll[10];
  stack<int> B,C;
  for(int i=0;i<N;i++){
    B.push(0); C.push(0);
    for(int j=0;j<10;j++) cin >> boll[j];
    for(int j=0;j<10;j++){
        if(boll[j]>B.top()) B.push(boll[j]);
        else if(boll[j]>C.top()) C.push(boll[j]);
        else{
          cout << "NO" << endl;
          break;
        }
        if(j==9) cout << "YES" << endl;
    }
  }
  return 0;
}

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

int a[10];

bool dfs(int id, int l_last, int r_last){
	if (id == 10)
		return true;
	if (a[id] > l_last && dfs(id + 1, a[id], r_last))
		return true;
	if (a[id] > r_last && dfs(id + 1, l_last, a[id]))
		return true;
	return false;
}

void solve(){
	if (dfs(0, -1, -1))
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

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