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 <bits/stdc++.h>
using namespace std;

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	int T; cin>>T;
	rep(_,T){
		vi a(10);
		rep(i,10) cin>>a[i];
		int x=0,y=0;
		bool ok=true;
		rep(i,10){
			if(min(x,y)>=a[i]){
				ok=false;
				break;
			}
			else if(x<a[i])
				x=a[i];
			else if(y<a[i])
				y=a[i];
		}
		cout<<(ok?"YES":"NO")<<endl;
	}
}

C++: #include <iostream>
#include <stack>

using namespace std;

int main() {
	int A[10];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 10; j++)
			cin >> A[j];
		stack<int> B, C;
		string ans = "YES";
		for (int j = 0; j < 10; j++) {
			int k = A[j];
			if (B.empty() == true && C.empty() == true)
				B.push(k);
			else if (B.empty() != true && C.empty() == true) {
//				if (B.top() < k)
//					B.push(k);
//				else
					C.push(k);
			}
			else {
				if (B.top() > k && C.top() > k) {
//					cout << k << " " << B.top() << " " << C.top() << endl;
					ans = "NO";
					break;
				}
				else if (B.top() > C.top())
					B.push(k);
				else
					C.push(k);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main() {
	int a, n, j;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a[10];
		stack<int> b, c;
		for (j = 0; j < 10; ++j) cin >> a[j];
		for (j = 0; j < 11; j++) {
			if (j == 10) {
				break;
			}
			if (j == 0) {
				b.push(a[j]);
			}
			else if (a[j] < b.top() && c.size() == 0) {
				c.push(a[j]);
			}
			else if (a[j] > b.top()) {
				b.push(a[j]);
			}
			else if (a[j] > c.top()) {
				c.push(a[j]);
			}
			else {
				break;
			}
		}
		if (j == 10) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
}

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

int array[10];
int n;
int i,j;
bool ans;

void dfs(int de,int b,int c)
{
	ans = false;

		if(de >= 10){
			ans = true;
			return;
		}

		if(b < array[de])
			dfs(de+1,array[de],c);
		if(c < array[de])
			dfs(de+1,b,array[de]);
}

int main()
{
	cin >> n;

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

		dfs(0,0,0);

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

	return 0;
}

C++: #include<iostream>
using namespace std;
int main(void)
{
int n;
cin>>n;
int b[10]={0};
int c[10]={0};
for(int i=0;i<n;i++)
{
	int a[10]={0};
	for(int j=0;j<10;j++)
	{
	int x;
	cin>>x;
	a[j]=x;
	}
	int k=0;
	for(int j=0;j<10-1;j++)
	{
	
	if(a[j]>a[j+1])
		{
		b[k]=a[j];
		k++;
		}
	else c[j]=a[j];
	}
	for(int i=0;i<10-1;i++)
	{
	if(b[i]>b[i+1] && b[i+1]!=0 && c[i]>c[i+1] && c[i+1]!=0)
	{
	cout<<"NO"<<endl;
	break;
	}
	else 
	{
	cout<<"YES"<<endl;
	break;
	}
	}
}
return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <stack>
using namespace std;
int a[10];
bool ans;
void dfs(int i,int r,int l){
	if(i==10)return;
	if(ans==0)return;
	if(r<a[i])dfs(i+1,a[i],l);
	if(l<a[i])dfs(i+1,r,a[i]);
	ans=0;
}
int main(){
	int t;
	cin>>t;
	while(t--){
		ans=1;
		for(int i=0;i<10;i++)cin>>a[i];
		dfs(0,0,0);
		if(ans)cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

C++: #include<iostream>
#include<cstring>
using namespace std;
int ball[10];
int l,r;
bool flag;
void dfs(int num,int l,int r){
	if(num==10) return ;
	if(flag) return ;
	if(ball[num]>l) dfs(num+1,ball[num],r);
	else if(ball[num]>r) dfs(num+1,l,ball[num]);
	else{
		flag=true;
		return ;
	}
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>ball[j];
		}
		l=0,r=0;
		flag=false;
	    dfs(i,l,r);
		if(flag){
			cout<<"NO"<<endl;
		}else{
			cout<<"YES"<<endl;
		} 
	}
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
void check(int x);
bool ans=false;
int a[12]={0};
int b=0,c=0,sub;
int main(void){

	int n;
	cin>>n;
	for(int q=0;q<n;q++){
	    for(int i=0;i<12;i++){
        a[i]=0;
        }
        ans=false;
        b=0,c=0,sub=0;

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


	check(0);
	if(ans==true)cout<<"YES"<<endl;
	else if(ans==false)cout<<"NO"<<endl;


	}
	return 0;
}
void check(int x){
    if(x==10){
        ans=true;
        return;
    }

    if(a[x]>b&&a[x]>c){
        sub=b;
        b=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        b=sub;

        sub=c;
        c=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        c=sub;
    }
    else if(a[x]>b){
        sub=b;
        b=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        b=sub;

    }
    else if(a[x]>c){
        sub=c;
        c=a[x];
        //cout<<x<<'('<<b<<'.'<<c<<')'<<endl;
        check(x+1);
        c=sub;

    }
    else {

        return;
    }

}

C++: #include <iostream>
using namespace std;
int main (){
       int N,a[20]={0},b[20]={0},t;
       cin>>N;
       for(int j=0;j<N;j++){
       int ac=0,bc=0;
       for(int i=0;i<10;i++){
              cin>>t;
              if(a[ac]<t){
                 a[ac+1]=t;
                 ac++;
               }
               else if(b[bc]<t){
                  b[bc+1]=t;
                  bc++;
                }
       
                else break;
     
           }
           if(ac+bc==10){
                 cout<<"YES"<<endl;
            }
           else cout<<"NO"<<endl;
           }
return 0;
}