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;
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) {
				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>
#include<stdio.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10  fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef long long ll;
const ll INF = 114514810;
const ll MOD = 1000000007;
const double EPS = 1e-8;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
//int dx[] = { -1, 0, 0, 1 }; int dy[] = { 0, -1, 1, 0 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///


int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		int l = 0, r = 0;
		bool f = true;
		REP(i, 10)
		{
			int t;
			cin >> t;
			if (t > l) l = t;
			else if (t > r) r = t;
			else f = false;
		}
		puts(f ? "YES" : "NO");
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <sstream> 
#define  ll long long
using namespace  std;
const    ll   len=105;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		vector<int>v1;
		vector<int>v2;
		int j=0;
		int w=0,temp;
		for(int i=0;i<10;i++)
		{
			cin>>temp;
			if(i==0)
				v1.push_back(temp);
			else
			{
				if(v1[v1.size()-1]<temp)
					v1.push_back(temp);
				else
				{
					if(v2.size()==0)
						v2.push_back(temp);
					if(v2[v2.size()-1]>temp&&v2.size()!=0)
						w=1;
					else
					if(v2[v2.size()-1]<temp&&v2.size()!=0)
						v2.push_back(temp); 	
				}  
			}
		}
		if(w==1)printf("NO\n");
		else
		 printf("YES\n");
	}
	return 0;
}

C++: #include <iostream>
#include <stdlib.h>
#include <queue>

using namespace std;

int main() {

	int n;
	int num[10];
	int min_A = 0, min_B = 0;
	int pos;

	while (cin >> n)
	{
		while (n-- > 0)
		{
			for (int i = 0; i < 10; i++)
			{
				cin >> num[i];
			}
			for ( pos = 0; pos < 10; pos++)
			{
				if (num[pos] > min_A)
				{
					min_A = num[pos];
				}
				else if (num[pos] > min_B)
				{
					min_B = num[pos];
				}
				else
				{
					break;
				}
			}
			if (pos == 10)
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
		}

	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;

int main(void)
{
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=0; i<n; i++) {
        int a[10];
        bool f = 0;
        for(int j=0; j<10; j++) cin >> a[j];
        for(int j=0; j<8; j++) {
            if(a[j] > a[j+1] && a[j+1] > a[j+2]) f = 1;
        }
        printf("%s\n", f ? "No" : "Yes");

    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10;
int num[N];
bool dfs(int i,int a,int b){
	if(i == N)	return true;
	if(num[i] > a)	if(dfs(i+1,num[i],b))	return true;
	if(num[i] > b)	if(dfs(i+1,a,num[i]))	return true;
	return false;
}
bool solve(){ return dfs(0,-1,-1); }
int main(){
	int T;	scanf("%d",&T);
	while(T--){
		for (int i = 0; i < N; ++i)	scanf("%d",num+i);
		if(solve())	puts("YES");
		else		puts("NO");
	}
}

C++: #include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;

#define PI         acos(-1.0)
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)

typedef long long ll;

int ball[10];
stack<int> r, l;

bool dfs(int n){
    if(n==10) return true;
    bool ret = false;
    // r?????\??????
    int rt = r.top();
    r.push(ball[n]);
    if(r.top()>rt){
        ret |= dfs(n+1);
        r.pop();
    }
    else r.pop();

    int lt = l.top();
    l.push(ball[n]);
    if(l.top()>lt){
        ret |= dfs(n+1);
        l.pop();
    }
    else l.pop();
    return ret;
}

int main(){
    int t;
    cin >> t;
    while(t--){
        while(!r.empty()) r.pop();
        while(!l.empty()) l.pop();
        r.push(0);
        l.push(0);
        FOR(i,0,10) cin >> ball[i];
        if(dfs(0)){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
    return 0;
}