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<cstdio>
#define ture 1
#define false 0
using namespace std;

int s[10],l[10],r[10];

bool slove(int i,int j,int k){

for(int i=1;i<10;i++)
{
    if(s[i]<l[j]&&s[i]<r[k]){
        return false;
    }
    if(s[i]>l[j]&&s[i]<r[k]){
        l[j+1]=s[i];
        j++;
    }
    if(s[i]<l[j]&&s[i]>r[k]){
        r[k+1]=s[i];
        k++;
    }
    else{
    if(s[i]-1==l[j]){
        l[j+1]=s[i];
        j++;
    }
    else if(s[i]-1==r[k+1]){
        r[k+1]=s[i];
        k++;
    }
    else if((s[i]-l[j])<(s[i]-r[k])){
        l[j+1]=s[i];
        j++;
    }
    else {
        r[k+1]=s[i];
        k++;
    }
    }
}
return true;
}







    /*
        if(k==10)
        return ture;
        if(l[i]>s[k]&&r[j]>s[k])
        return false;
        l[i+1]=s[k];
        r[j+1]=s[k];
        if(slove(i,j+1,k+1)&&r[j]<s[k])
            {
                l[i+1]=0;
                return ture;
            }
            else if(slove(i+1,j,k+1)&&l[i]<s[k])
            {
                r[j+1]=0;
                return ture;
            }
            else
                return false;*/


int main()
{
    int N;
    scanf("%d",&N);
    while(N--)
    {
        for(int i=0;i<10;i++)
            {
                scanf("%d",&s[i]);
                l[i]=0;
                r[i]=0;
            }
            l[0]=s[0];
        if(slove(0,0,1))
            printf("YES\n");
        else
            printf("NO\n");
    }
    return 0;
}

C++: #include <cstdio>
using namespace std;
int n;
int a[11];
int main() {
    scanf("%d", &n);
    for (int t = 0; t < n; ++t) {
        int l = 0, r = 0;
        for (int i = 0; i < 10; ++i) scanf("%d", &a[i]);
        bool flag=false;
        for (int i = 0; i < 10; ++i) {
            if (r > l) {
                if (a[i] > r) r = a[i];
                else if (a[i] > l) l = a[i];
                else flag=true;
            } else {
                if (a[i] > l) l = a[i];
                else if (a[i] > r) r = a[i];
                else flag=true;
            }
        }
        if (flag) printf("NO");
        else printf("YES");

    }
    return 0;
}

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

int main() {
	int n;
	int d[10];
	int va[10];
	int vb[10];

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

		int ca = 0, cb = 0;
		va[0] = d[0];
		ca++;
		if (d[1] > va[0]) {
			va[1] = d[1];
			ca++;
		}

		else {
			vb[0] = d[1];
			cb++;
		}

	for (int j = 2; j < 10; j++) {

			if (d[j] > va[ca-1]) {
				va[ca] = d[j];
				ca++;
			}

			else if (d[j] > vb[cb-1]) {
				vb[cb] = d[j];
				cb++;
			}

			else {
				goto FINLOOP;
			}

		}

	FINLOOP:

	if (ca + cb == 10) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

		for (int i = 0; i < 10; i++) {
			va[i] = 0;
		}
		for (int i = 0; i < 10; i++) {
			vb[i] = 0;
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=(0);(i)<(int)(n);++(i))
using ll = long long;
using P = pair<int, int>;
using namespace std;

int a[11];
bool ok = false;

void solve(int i, vector<int> x, vector<int> y) {
    if(i >= 10) {
        bool tmp = true;

        rep(j, x.size()-1) {
            if (x[j] > x[j+1]) tmp = false;
        }
        rep(j, y.size()-1) {
            if (y[j] > y[j+1]) tmp = false;
        }

        ok |= tmp;
        return;
    }

    x.push_back(a[i]);
    solve(i+1, x, y);
    x.pop_back();
    y.push_back(a[i]);
    solve(i+1, x, y);
    y.pop_back();

    return;
}

int main() {
    int n;
    cin >> n;
    rep(i, n) {
        rep(j, 10) cin >> a[j];
        ok = false;
        vector<int> x, y;
        solve(0, x, y);
        cout << (ok ? "YES" : "NO") << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int a[10],n;

bool dfs(int i,int j,int k)
{
    if(i==10) return 1;
    if(a[i]>j&&a[i]>k) return dfs(i+1,a[i],k) || dfs(i+1,j,a[i]);
    else if(a[i]>j) return dfs(i+1,a[i],k);
    else if(a[i]>k) return dfs(i+1,j,a[i]);
    return 0;
}

int main()
{
    //mine
    ios::sync_with_stdio(false);
    cin>>n;
    while(n--){
        for(int i=0;i<10;i++) cin>>a[i];
        if(dfs(0,0,0)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
    return 0;
}

C++: //
// Created by yijiezhu on 12/20/16.
//

#include <bitset>
#include <iostream>
using namespace std;

int n, ball[10];

bool valid(int iter) {
    int left = 0, right = 0;
    auto bs = bitset<10>(iter);
    for (int i = 0; i < 10; i++) {
        if (bs[i]) {
            if (ball[i] < left) return false;
            left = ball[i];
        } else {
            if (ball[i] < right) return false;
            right = ball[i];
        }
    }
    return true;
}

int main() {
    cin >> n;
    while (n-- > 0) {
        for (int i = 0; i < 10; i++) {
            cin >> ball[i];
        }
        bool found = false;
        for (int iter = 0; iter < (1 << 10); iter++) {
            if (valid(iter)) {
                cout << "YES\n";
                found = true;
                break;
            }
        }
        if (!found) cout << "NO\n";
    }
}

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

int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		int k = 10;
		int x = 0, y = 0;
		int i;
		bool flag = true;
		while (k--)
		{
			cin >> i;
			if (i > y) y = i;
			else if (i > x) x = i;
			else flag = false;
		}
		if (flag) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

C++: #include<stdio.h>
int main(void)
{
	int n, i, j;
	int ball[10], blast = 0, clast = 0, min = 11, m = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
	{
		for (j = 0; j < 10; j++)
		{
			scanf("%d" , &ball[j]);
		}
		blast = ball[0];
		for (j = 1; j < 10; j++)
		{
			if (blast < ball[j])
				blast = ball[j];
			else if (clast < ball[j])
				clast = ball[j];
			else
			{
				m = 1;
				break;
			}
		}
		if (m == 1)
		{
			printf("NO\n");
			m = 0;
		}
		else
		{
			printf("YES\n");
		}

	}
	return 0;
}

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

using namespace std;

typedef vector<int> VI;

bool dfs(const VI &balls, int idx, int l, int r) {
  if (idx >= 10) return true;
  int n = balls[idx];
  if (n > l && dfs(balls, idx+1, n, r)) return true;
  if (n > r && dfs(balls, idx+1, l, n)) return true;
  return false;
}

void solve() {
  VI balls;
  for (int i = 0; i < 10; i++) {
    int n;
    cin >> n;
    balls.push_back(n);
  }
  if (dfs(balls, 0, 0, 0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    solve();
  }

  return 0;
}