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 ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

int n;
int a[11];

void bitBruteForth() {
   bool printed = false;
   rep (mask, (1<<10)) {
      bool ok = true;
      int oldA = -1, oldB = -1;
      rep (j, 10) {
         if ((mask>>j)&1) {
            if (a[j] > oldA) {
               oldA = a[j];
            } else {
               ok = false;
            }
         } else {
            if (a[j] > oldB) {
               oldB = a[j];
            } else {
               ok = false;
            }
         }
      }
      if (ok) {
         puts("YES");
         printed = true;
         break;
      }
   }
   if (!printed) puts("NO");
}

bool rec(int idx, int l, int r) {
   if (idx == 10) return true;

   bool x = false, y = false;
   int val = a[idx];
   if (l < val) x = rec(idx+1, val, r);
   if (r < val) y = rec(idx+1, l, val);

   return x || y;
}

int main() {
   cin >> n;
   while (n--) {
      rep (i, 10) cin >> a[i];
      puts(rec(0, -1, -1)?"YES":"NO");
   }

   return 0;
}

C++: #include <iostream>
int a[20];
using namespace std;
bool dfs(int i,int b,int c)
{
    if (i == 11) return true;
    if (a[i] > b) if(dfs(i + 1,a[i],c)) return true;
    if (a[i] > c) if(dfs(i + 1,b,a[i])) return true;
    return false;
}
int main()
{
    int n;
    cin >> n;
    while (n--)
    {
        for (int i = 1; i <= 10; ++i)
            cin >> a[i];
        if (dfs(1, 0, 0)) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

int main(){
	int b, c, n, a, i, j;
	bool executable;
	cin >> n;
	for(i=0;i<n;i++){
		executable = true;
		cin>>a;
		b=a;
		c=0;
		for(j=1;j<10;j++){
			cin>>a;
			if(a-b < 0){
				if(a-c < 0){
					executable = false;
				}else{
					c = a;
				}
			}else{
				if(a-c < 0){
					b = a;
				}else{
					if(c < b){
						b = a;
					}else{
						c = a;
					}
				}
			}
		}
		if(executable){
			cout << "YES\n";
		}else{
			cout << "NO\n";
		}
	}
	return 0;
}

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

int main(){
  int n=0;
  int a[10];
  int ans=0;
  cin>>n;
  //  while(scanf("%d %d %d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&a[4],&a[5],&a[6],&a[7],&a[8],&a[9])){
  for(int j=0;j<n;j++){
    for(int k=0;k<10;k++){
      cin>>a[k];
    }
    ans=0;
    int l=0,r=0;
    for(int i=0;i<10;i++){
      if(i==0){
	l=a[i];
      }
      else{
	int ma=max(l,r);
	int mi=min(l,r);
	if(a[i]>ma){
	  if(l==ma){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else if(mi<a[i]&&a[i]<ma){
	  if(l==mi){
	    l=a[i];
	  }
	  else{
	    r=a[i];
	  }
	}
	else{
	  break;
	}
      }
      if(i==9){
	ans=1;
      }
    }

    if(ans==1){
      cout<<"YES\n";
    }
    else{
      cout<<"NO\n";
    }
  }
  return 0;
}

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

using namespace std;
vector<int> ball;
bool search(int l, int r, int n)
{
  if (n == 10) {
    return true;
  }

  if (l < ball[n]) {
    if (search(ball[n], r, n + 1)) {return true;}
  } 
  if (r < ball[n]) {
    if (search(l, ball[n], n + 1)) {return true;}
  }
  return false;
}

int main()
{
  int N;
  scanf("%d ", &N);
  
  for (int i = 0; i < N; i++) {
    ball.clear();
    ball.resize(10);
    for (int i = 0; i < 10; i++) {
      scanf("%d ", &ball[i]);
    }
    if (search(ball[0], 0, 1)) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define foreach(itr,a) for(__typeof((a).begin()) itr=(a).begin(); itr!=(a).end(); itr++)
#define ALL(x) (x).begin(), (x).end()
#define pb push_back

int a[11];

void dfs(int depth, int l, int r) {
    if(depth == 10) {
        cout << "YES" << endl;
        return ;
    }

    int t = a[depth];
    if(l < t)
        dfs(depth+1, t, r);
    else if(r < t)
        dfs(depth+1, l, t);
    else
        cout << "NO" << endl;

    return ;
}

int main() {
    int n; cin >> n;
    rep(poyo,n) {
        rep(i,10) cin >> a[i];
        dfs(0,0,0);
    } 

    return 0;
}

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

int main(){
	int n,ball,tp[2],con,bad;
	
	cin >> n;
	
	for(; n > 0; n--){
		
		tp[0] = tp[1] = 0;
		
		for(int i = 0; i < 10; i++){
			cin >> ball;
			
			if(tp[0] > tp[1]){
				con = 0;
			}else{
				con = 1;
			}
			
			if(ball > tp[con]){
				tp[con] = ball;
			}else if(ball > tp[!con]){
				tp[!con] = ball;
			}else{
				cout << "NO" << endl;
				cin.ignore(64, '\n');
			}
			
			if(i == 9){
				cout << "YES" << endl;
			}
		}
	}
	
	return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	vector<bool>l;
	int o[10], n;
	cin >> n;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++)
			cin >> o[i];
		int sum = o[i], num = 0;
		for (int k = 0; k < 10;k++) {
			if (o[k] < sum){
				num++;
				sum = o[k];
			}
		}
		l.push_back(!(num >= 2));
	}
	for (bool b : l) {
		if (!b)cout << "YES";
		else cout << "NO";
		cout << endl;
	}
	char c;
	cin >> c;
}