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 <queue>
using namespace std;
int ball[10];
int dfs(int k,int B,int C)
{
    if(k == 10)
        return 1;
    if(ball[k] > B)
        return dfs(k + 1,ball[k],C);
    if(ball[k] > C)
        return dfs(k + 1,B,ball[k]);
    return 0;
}
int main(void)
{
    int n;
    cin>>n;
    while(n--){
        int i;
        queue<int> left,right;
        for(i = 0;i < 10;i++)
            cin>>ball[i];
        if(dfs(0,0,0))
            cout<<"YES"<<endl;
        else
            cout<<"NO"<<endl;
    }
    return 0;
}

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

int BALLNUM = 10;

	static int data[10];
class balldata
{
private:
	//static std::vector <int> data;
	//int ballnum;
public:
	balldata(int datanum);
	static void enter();
	static void answer();
	static bool check();
	static bool check(int num,int right,int left);
};




int main()
{
	balldata ball(BALLNUM);

int N;
	std::cin >> N;
	for (int i = 0; i < N; i++)
	{
		ball.enter();
		ball.answer();
	}
}


balldata::balldata(int datanum)
{
	//ballnum = datanum;
	//data.resize(datanum);
}



void balldata::enter()
{
	for (int i = 0; i < 10; i++)
	{
		std::cin >> data[i];
	}
	return;
}

bool balldata::check(int num,int right,int left)
{
	//if (num == data.size())return true;
	if (num == 10)return true;
	if (balldata::check(num + 1, right, data[num])&&left<data[num]){ return true; }
	if (balldata::check(num + 1, data[num], left)&&right<data[num]){ return true; }

	return false;
}
bool check()
{
	return balldata::check(0, 0, 0);
}

void balldata::answer()
{ 
	if (balldata::check(0, 0, 0))
	{
		std::cout << "YES" << std::endl;
	}
	else
	{
		std::cout << "NO" << std::endl;
	}
}

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;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr 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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
	int n;
	cin >> n;
	rep(i, n) {
		stack<int> l, r;
		rep(j, 10) {
			int x;
			cin >> x;
			if (l.size() == 0) {
				l.push(x);
				continue;
			}
			if (r.size() == 0) {
				if (l.top() < x) {
					l.push(x);
					continue;
				}
				r.push(x);
				continue;
			}
			if (l.top() < r.top()) {
				if (r.top() < x) {
					r.push(x);
					continue;
				}
				if (l.top() < x) {
					l.push(x);
					continue;
				}
			}
			if (r.top() < l.top()) {
				if (l.top() < x) {
					l.push(x);
					continue;
				}
				if (r.top() < x) {
					r.push(x);
					continue;
				}
			}
			cout << "NO" << endl;
			goto a;
		}
		cout << "YES" << endl;
a:;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

int main(){
	int T;
	cin >> T;
	while(T--){
		int a=0,b=0;
		string ans = "YES";
		for(int i = 0 ; i < 10 ; i++){
			if( a > b ) swap(a,b);
			int x;
			cin >> x;
			if( x < a ){
				ans = "NO";
			}else if( b < x ){
				b = x;
			}else{
				a = x;
			}
		}
		cout << ans << endl;
	}
	
}

C++: #include<stdio.h>
int a[10];
int bstack[10];
int btop;
int cstack[10];
int ctop;
bool dfs(int i)
{
    bool b1=false,b2=false;
    if(i==10)
        return true;
    if(btop==-1 || bstack[btop]<a[i])
    {
        btop++;
        bstack[btop]=a[i];
        i++;
        b1=dfs(i);
        btop--;
    }
    if(ctop==-1 || cstack[ctop]<a[i])
    {
        ctop++;
        cstack[ctop]=a[i];
        i++;
        b2=dfs(i);
        ctop--;
    }
    return b1||b2;
}
int main()
{
    int n;
    scanf("%d",&n);
    while(n--)
    {
        for(int i=0;i<10;i++)
        {
            scanf("%d",&a[i]);
        }
        btop=-1;
        ctop=-1;
        if(dfs(0))
            printf("YES\n");
        else
            printf("NO\n");
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
main(){
  int n,a;
  srand((unsigned)time(NULL));
  cin>>n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin>>a;
    }
    if(rand()%2==0){
      cout<<"YES"<<endl;
    }
    else{
      cout<<"NO"<<endl;
    }
  }
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <queue>
using namespace std;
int a[11];
int a1[11];
int pn=0;
int Flag;
void dfs(int i)
{
    if(Flag==1)
        return;

    if(a[i]>a[a1[pn]])
    {
        a1[++pn]=i;
        for(int m=i+1;m<=10;m++)
        {
            dfs(m);
        }
    }
    else
        return;
    int flag=0;
    for(int m=i+1;m<=10;m++)
    {
        if(a[m]>a[i])
            flag=1;
    }
    int flag2;
    if(flag==0||i==10)
    {
        int a2[11];
        int pm=0;
        for(int n=1;n<=10;n++)
        {
            flag2=0;
            for(int m=1;m<=pn;m++)
            {
                if(n==a1[m])
                   flag2=1;
            }
            if(!flag2)
            {
               a2[++pm]=n;
            }
        }
        int flag3=0;
        for(int m=1;m<pm;m++)
        {
            if(a[a2[m]]>a[a2[m+1]])
                flag3=1;
        }
        if(flag3==0)
        {
            Flag=1;
            return;
        }
        else
        {
            pn--;
            return;
        }
    }

}
int main()
{
    int n;
    
    scanf("%d",&n);
    getchar();
    a[0]=-1;
    a1[0]=0;
    for(int i=1;i<=n;i++)
    {
        Flag=0;
        pn=0;
        for(int j=1;j<=10;j++)
        {
            scanf("%d ",&a[j]);
        }
        dfs(1);
        if(Flag==0)
        {
            printf("NO\n");
        }
        else
            printf("YES\n");
    }
    return 0;
}