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++: // scnucjh
// AOJ 0033
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int n;
vector<int> B,C;
int A[10];
bool flag; //是否有解

void dfs(int x) {
	if(x==10) { //球丢完了，递归要返回
		for(int i=1;i<B.size();i++) {
			if(B[i]<B[i-1]) return; //这个分支不行,有矛盾
		}
		for(int i=1;i<C.size();i++) {
			if(C[i]<C[i-1]) return; //这个分支不行,有矛盾
		}
		flag = true; 			 //这个分支走到最后是有解的
		return;
	}
	B.push_back(A[x]); 			//把第x个球丢给B
	dfs(x+1);  					//进入这个分支
	B.pop_back(); 				//撤销操作，弹出B的最后一个球
	
	C.push_back(A[x]); 			//把第x个球丢给C
	dfs(x+1);    				//进入这个分支
	C.pop_back(); 				//撤销操作，弹出C的最后一个球
}

int main() {
	int T;
    scanf("%d",&T);
	while(T--) {
		for(int i=0;i<10;i++) scanf("%d",&A[i]);
		flag = false;
		dfs(0);
		puts(flag ? "YES":"NO");
	}
    return 0;
}

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

int ball[10];

bool solve(int i, int a, int b){
	if (i == 10) return true;
	bool ans = false;
	if (a < ball[i]) ans = solve(i + 1, ball[i], b);
	if (b < ball[i])ans = solve(i + 1, a, ball[i]);
	return ans;
}

int main(){
	int n;
	cin >> n;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < 10; j++){
			cin >> ball[j];
		}
		if (solve(0, 0, 0)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}

	return 0;
}
//beatmaniaIIDX 23th copula

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

int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		bool z = true;
		int a[10];
		for(int j=0;j<10;j++) cin >> a[j];
		int b = 0;
		int c = 0;
		for(int j=0;j<10;j++){
			if(b>a[j] and c>a[j]) z = false;
			if(not z) break;
			if(b>c){
				if(b>a[j]) c = a[j];
				else b = a[j];
			}
			else{
				if(c>a[j]) b = a[j];
				else c = a[j];
			}
		}
		if(z) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

int main() {
int a[10],b[11],c[11];
int n;
cin>>n;
for (int jjj=1;jjj<=n;jjj++){
	for(int kk=0;kk<10;kk++) cin>>a[kk];
int bb=0,cc=0;
b[0]=0;
c[0]=0;
for (int k=0;k<10;k++){
	if(a[k]>b[bb] && b[bb]>=c[cc]){
		b[bb+1]=a[k];
		bb=bb+1;
	}
	else{
		c[cc+1]=a[k];
		cc=cc+1;
	}
}
	int l=0,m=0;
	for(int i=1;i<bb;i++){
		if(b[i]-b[i-1]<0){
			l=2;
		}
	}
	for(int j=1;j<cc;j++){
		if(c[j]-c[j-1]<0){
			m=2;
		}
	}
	if(l+m==0){
		cout<<"YES"<<endl;
	}
	else{
		cout<<"NO"<<endl;
	}
	
}

	return 0;
}

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

int b[10],c[10],bi,ci,flag;

int main()
{
    int n,ball;
    scanf("%d", &n);
    for(int I=0;I<n;++I) {
        for(int i=0;i<9;++i) {
            scanf("%d", &ball);
            if (!bi) { b[bi] = ball; ++bi; continue; }
            else if (!ci) { c[ci] = ball; ++ci; continue; }
            else if (b[bi] < ball) {
                ++bi;
                b[bi] = ball;
            } else if (c[ci] < ball) {
                ++ci;
                c[ci] = ball;
            } else {
                ++flag;
                break;
            }
        }
        (flag) ? puts("NO") : puts("YES");
    }

    return 0;
}

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

using namespace std;

bool check(const vector<int> & ary,int i,int l,int r)
{
	if(i == 10)
		return true;
	bool f = false;
	if(ary[i] > l)
	{
		f = check(ary,i+1,ary[i],r);
	}
	if(ary[i] > r)
	{
		f = f || check(ary,i+1,l,ary[i]);
	}
	return f;
}

int main (int argc, char const* argv[])
{
	int n;
	cin >> n;
	for (unsigned int i = 0; i < n; i += 1)
	{
		auto ary = vector<int>(10);
		for (unsigned int i = 0; i < 10; i += 1)
		{
			cin >> ary[i];
		}
		bool f = check(ary,0,0,0);
		if(f)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
	return 0;
}

C++: #include<iostream>
int topA=-1, topB=-1,B;
int times;
int main(){
	std::cin >> times;
	for (int j = 0; j < times; j++){
		for (int i = 0; i < 10; i++){
			std::cin >> B;
			if (topA == -1 && topB == -1){
				topA = B;
			}
			else if (topA != -1 && topB == -1){
				topB = B;
			}
				else if (topA < B){
					topA = B;
				}
				else if (topB < B){
					topB = B;
				}
				else{
					std::cout << "NO\n";
					goto rip;
				}
			}
		std::cout << "YES\n";
	rip:;
		}

}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	int n;
	scanf("%d", &n);
	rep(i, n){
		bool can = true;
		int left = 0, right = 0;
		rep(j, 10){
			int a;
			scanf("%d", &a);
			if(min(left, right) > a){
				can = false;
			}
			if(max(left, right) < a){
				if(left<right) right = a;
				else left = a;
			}else{
				if(left<right) left = a;
				else right = a;
			}
		}

		puts(can ? "YES" : "NO");
	}

	return 0;
}

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

int main(){
    int n,ball,fb;
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        int x[11] = {0} , y[11] = {0};
        int flg = 0;
        
        cin >> fb;
        x[0] = fb;
        for(int j = 1 ; j < 10 ; j++){
            cin >> ball;
            if(x[j-1] < ball){
                x[j] = ball;
                y[j] = y[j-1];
            }
            else if(y[j-1] < ball){
                y[j] = ball;
                x[j] = x[j-1];
            }
            else flg = 1;
        }
    
        if(flg==0) cout << "YES" << endl;
        else cout << "NO" << endl;
        
    }


    return 0;
}

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

//global
const int MAX_N = 10;
int a[MAX_N];



bool dfs(int i, int b, int c) {
	if (i == MAX_N)return true;
	if (b < a[i] && dfs(i + 1, a[i], c))return true;
	if (c < a[i] && dfs(i + 1, b, a[i]))return true;
	return false;

}


//solve
void solve()
{
	int b = a[0];
	int c = 0;
	cout << (dfs(1, b, c) ? "YES" : "NO") << endl;
}



//main
int main()
{
	int tcase;
	cin >> tcase;
	while (tcase--) {
		for (int i = 0; i < 10; i++) {
			cin >> a[i];
		}
		solve();
	}
    return 0;
}